Score:0

How to prevent ssh user to login if same user is still logged in?

im flag

For security reasons, I want to restrict users to have more than one ssh connection. In terminal, if I check $ last user , I'll find the user is still logged in. Is any solution to check if user is still logged in don't allow to login again?

in flag
https://unix.stackexchange.com/questions/127077/number-of-ssh-connections-on-a-single-linux-machine
in flag
Does this answer your question? [sftp concurrent connection](https://serverfault.com/questions/392749/sftp-concurrent-connection)
Romeo Ninov avatar
in flag
@GeraldSchneider, IMHO the fist is better match :)
in flag
IMO as well, but we can't close as a duplicate on a different site. The second answers it as well and it's not necessary to replicate the answer.
Score:1
in flag

You can't directly limit the ssh connections. But you can limit the logins of this user. Edit /etc/security/limits.conf and add line:

specificuser  hard    maxlogins   1

This will limit the logins to 1 for specificuser (independently if we talk about ssh, telnet or console logins)

Score:0
tl flag

Configure the option "MaxStartups " in the "/etc/ssh/sshd_config file":

MaxStartups 1

Then restart the ssh service. This setting allows a maximum of one connection for each user

https://man7.org/linux/man-pages/man5/sshd_config.5.html

Score:0
iq flag

If you are using the same user for all users on your company (aka root), you can add the next code on the begging of the /etc/profile file to filter one user by IP address:

# Limit logins to one user by IP
NEW_LOGIN=$(last -n 1 | head -n 1 | awk '{print $3}')
CURRENT_LOGINS=$(w -hs | awk '{print $3}' | grep "$NEW_LOGIN" | wc -l)
if [ "$CURRENT_LOGINS" -ge "2" ]; then
  echo "Only one login per user/IP is allowed, closing this connection to $NEW_LOGIN"
  exit 1
fi
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.