Find the IP address of the client in an SSH session

后端 未结 19 1035
刺人心
刺人心 2020-12-12 10:48

I have a script that is to be run by a person that logs in to the server with SSH.

Is there a way to find out automatically what IP address the user is connecting fr

19条回答
  •  眼角桃花
    2020-12-12 11:18

    I'm getting the following output from who -m --ips on Debian 10:

    root pts/0 Dec 4 06:45 123.123.123.123

    Looks like a new column was added, so {print $5} or "take 5th column" attempts don't work anymore.

    Try this:

    who -m --ips | egrep -o '([0-9]{1,3}\.){3}[0-9]{1,3}'
    

    Source:

    • @Yvan's comment on @AlexP's answer
    • @Sankalp's answer

提交回复
热议问题