Find the IP address of the client in an SSH session

后端 未结 19 1068
刺人心
刺人心 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:30

    One thumb up for @Nikhil Katre's answer :

    Simplest command to get the last 10 users logged in to the machine is last|head.

    To get all the users simply use last command

    The one using who or pinky did what is basically asked. But But But they don't give historical sessions info.

    Which might also be interesting if you want to know someone who has just logged in and logged out already when you start this checking.

    if it is a multiuser system. I recommand add the user account you are looking for:

    last | grep $USER | head
    

    EDIT:

    In my case, both $SSH_CLIENT and $SSH_CONNECTION do not exist.

提交回复
热议问题