How can I track who SSH'es into my linux machine?

60,224

Solution 1

The information of who logged in when is available in /var/log/auth.log (or other log files on other distributions). There are multiple log monitoring programs that can extract the information you configure as relevant. On any sane system, every user authentication is logged.

To log every command invocation (but not their arguments), use process accounting, provided by the acct package Install acct on Ubuntu. If the accounting subsystem is up and running, then lastcomm shows information about finished processes.

Solution 2

You can also use who or w to see who is currently logged in to the system, including SSH users.

Solution 3

You can also try entering the command last into the console, which displays all recent log-ins, including the user name they logged in under (but does not record if they changed their user name after logging in), IP, date, and duration of time logged in.

This command was mentioned by @jasonwryan in a comment here.

Share:
60,224

Related videos on Youtube

cwd
Author by

cwd

Updated on September 18, 2022

Comments

  • cwd
    cwd over 1 year

    I'm running Ubuntu 10.04. Is there a way I can get a daily report of who has logged onto the box, what time, and even - this may be asking too much - a report of the commands they used? This is a low-usage box and so I think this would be a nice way to see what activity is happening on it.

    Along these same lines, I heard it was not possible to track when things are done on the box via non-interactive shells, such as rsync or just remotely executing single commands via ssh. Is that true, or is there a way to log and track this as well?

  • Adrian Cornish
    Adrian Cornish over 12 years
    /var/log/secure.log is another common logfile
  • jasonwryan
    jasonwryan over 12 years
    last might be a better option for what the OP was looking for...
  • Sirex
    Sirex over 12 years
    indeed. "last" is the command you want.
  • PaulBGD
    PaulBGD almost 10 years
    This is a MUCH better answer then the selected one.
  • mcdoomington
    mcdoomington almost 8 years
    Fine. I will update it.
  • Merlin
    Merlin over 4 years
    I could not find the appropriate log file, last was exactly what I needed.
  • Dizzie KX
    Dizzie KX about 3 years
    cat: /var/log/messages: No such file or directory