How to identify SSH user interactive login?

Julio Jose
Julio Jose used Ask the Experts™
on
Hi, on windows we can check the event log for login event that is login type 3 RDP interactive login session.

On Linux and Unix OS, I need to detect SSH user interactive login where the user login from laptop / pc but not the ssh session initial by the script, the common is wtmp log,  is that a way to identify?

root     pts/1        1.1.1.1       Thu Aug  4 09:35 - 14:45  (05:09)

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Gerwin Jansen, EE MVETopic Advisor
Most Valuable Expert 2016

Commented:
Did you try the who command? Does it show what you're after?
Hello

You can also run the following
w
who
wall (then ask them what they are ing and who they are)

Always create users and make them perform sudo or su for root access.

Hope this helps

Thanks

Author

Commented:
I need to identify this user session from the log but not run any other command
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Hello

Try to view the log below

tail /var/log/secure

Or you can try
tail /var/log/secure | grep root

Author

Commented:
I can check the secure log for the root user but how do I know if root user are login via the script or application, I only need to capture if user login from the laptop / pc ssh client interactive login.
Gerwin Jansen, EE MVETopic Advisor
Most Valuable Expert 2016

Commented:
Which exact Linux version is this about? On Ubuntu for example, you have to look at /var/log/auth.log - lines with sshd in it.

Author

Commented:
interest on RHEL 4,5,6, Solaris and AIX
Gerwin Jansen, EE MVETopic Advisor
Most Valuable Expert 2016

Commented:
It is /var/log/secure on Red Hat - about the others: AIX should be in syslog, Solaris as well (but has to be configured in syslog.conf).

Author

Commented:
I tried SFTP and SSH both having same log in the "secure" I need to identify which one actually user login from the SSH client software
Gerwin Jansen, EE MVETopic Advisor
Most Valuable Expert 2016

Commented:
You are very unclear, first you talk about a script, now sftp. Both ssh and sftp use the same port (ssh). I do not understand what you want.

Author

Commented:
apologize, I want to check exiting log for real user login with password using SSH client software
Hello,


I think with the answers posted that should get you what you need.

Or are you wanting to be alerted by some way when someone does login to the Server?
If so you are looking for a script or crontab job.  This will get more complex but can be done.

I have a script when ever someone logs in as root or su's in to send me an email
If someone starts an interactive session via ssh (or, $DEITY forbid, telnet), whether using the password or an ssh key,  it's logged in wtmp (on AIX, HP-UX and Linux and I believe Solaris as well), and the `last` command will show that session.

If some runs `ssh root@yourserver "command"`, it's logged in syslog but not wtmp. That's still a security issue  - Someone has direct root login and is using it, but it's harder to detect.

Setting PermitRootLogin = no in sshd_config solves the problem

Author

Commented:
So we should check WTMP to identify the user SSH interactive session?
Yes, if you're only interested in interactive sessions, `last` will show you the contents of wtmp.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial