Ssh session terminates, when login command is used

We have a Virtual Machine with underlying OS as Alma 9.x.
I am facing an issue where ssh session terminates, when we use login command.

Steps to reproduce.

  1. SSH to the VM.
  2. Run login command.-> This terminates SSH session

I tried using exec login, but it didn’t work reference login(1) - Linux manual page

BUGS top

Just reproduced the same error and can confirm this is happening on AlmaLinux 9.3. Here is the journal:

Mar 16 16:21:18 test sshd[3787]: pam_unix(sshd:session): session opened for user root(uid=0) by (uid=0)
Mar 16 16:21:35 test sshd[3821]: Accepted password for root from XX.XX.XXX.XX port 47388 ssh2
Mar 16 16:21:35 test systemd-logind[540]: New session 5 of user root.
Mar 16 16:21:35 test systemd[1]: Started Session 5 of User root.
Mar 16 16:21:35 test sshd[3821]: pam_unix(sshd:session): session opened for user root(uid=0) by (uid=0)
Mar 16 16:21:45 test sshd[3823]: Received disconnect from XX.XX.XXX.XX port 47388:11: disconnected by user
Mar 16 16:21:45 test sshd[3823]: Disconnected from user root XX.XX.XXX.XX port 47388
Mar 16 16:21:45 test sshd[3821]: pam_unix(sshd:session): session closed for user root
Mar 16 16:21:45 test systemd[1]: session-5.scope: Deactivated successfully.
Mar 16 16:21:45 test systemd-logind[540]: Session 5 logged out. Waiting for processes to exit.
Mar 16 16:21:45 test systemd-logind[540]: Removed session 5.

Let me debug this and get back to you!

Happens with all versions, Alma 8 and CentOS 7 as well! The most likely cause I see is that SSH itself handles authentication of remote user whereas login command is made for local system authentication. When you use the login command over SSH, it’s trying to prompt for a username and password on the remote system, but since the SSH session is already established, it doesn’t handle this input correctly, resulting in the termination of the SSH connection.

Just a check, why do you use the login command?
(There could be other commands that achieve the same goal.)

1 Like

Thanks @ankesh this makes sense, i can use other alternatives to login.
I am facing one more problem related to login command, sharing the link here if you could have a look.