How to Determine the IP Address of who logged into Root

rootSecurity

There are several people with root access to a particular VM I am in charge of. I would like to find out which IP address was used to log into root.

Best Answer

You can use the last command to get this information

# last|head
phemmer  ssh          192.168.0.24     Wed Aug 20 21:08 - 21:08  (00:00)
phemmer  pts/13       192.168.0.2      Wed Aug 20 14:00 - 18:43  (04:43)
phemmer  ssh          192.168.0.2      Wed Aug 20 14:00 - 18:43  (04:43)
phemmer  ssh          ::1              Wed Aug 13 23:08 - 23:08  (00:00)
phemmer  ssh          ::1              Wed Aug 13 23:08 - 23:08  (00:00)
phemmer  ssh          ::1              Wed Aug 13 23:07 - 23:07  (00:00)
phemmer  pts/15       192.168.0.20     Thu Aug  7 19:00 - 19:00  (00:00)
phemmer  ssh          192.168.0.20     Thu Aug  7 19:00 - 19:00  (00:00)
phemmer  :0                            Wed Jul 30 20:06   still logged in
reboot   system boot  3.13.2-gentoo    Wed Jul 30 20:05   still running

As you can no doubt see, the 3rd column will show the remote IP address in the event of an SSH login.

last uses the /var/log/wtmp file, so this method is similar to G-Man's answer (just a bit simpler since you don't have to specify the path to the file).

Related Question