Avatar of Julio Jose
Julio Jose
Flag for Malaysia asked on

How to identify SSH user interactive login?

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

LinuxLinux Networking

Avatar of undefined
Last Comment
tfewster

8/22/2022 - Mon
Gerwin Jansen

Did you try the who command? Does it show what you're after?
Steven Roman

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
Julio Jose

ASKER
I need to identify this user session from the log but not run any other command
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Steven Roman

Hello

Try to view the log below

tail /var/log/secure

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

ASKER
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

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.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Julio Jose

ASKER
interest on RHEL 4,5,6, Solaris and AIX
Gerwin Jansen

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).
Julio Jose

ASKER
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
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Gerwin Jansen

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.
Julio Jose

ASKER
apologize, I want to check exiting log for real user login with password using SSH client software
Steven Roman

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
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
tfewster

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
Julio Jose

ASKER
So we should check WTMP to identify the user SSH interactive session?
ASKER CERTIFIED SOLUTION
tfewster

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.