I have a 18.04 Ubuntu server that I use to bypass internet filtering/censorship in my country using SSH tunneling. To do this, I have created several users using the command adduser USERNAME --shell=/bin/false
and given them the server IP, server port, username, and password (which I call them an account), so they can tunnel through my server. Now I want to make sure each account only works on one device at a time. In other words, I want to prevent multiple devices from tunneling through my server simultaneously using the same account.
By googling I found a solution: I put the following to, say, file /root/checkConnections
:
#! /bin/bash
limit=$1
c=$(pgrep -xcu $PAM_USER sshd)
if [[ $c -ge "$limit" ]]; then
echo "Max $limit ssh connections allowed, but you have $c."
exit 1
fi
Then in /etc/pam.d/sshd
I added:
session required pam_exec.so stdout /root/checkConnections 1
This code worked well and did exactly what I wanted, but it has a significant drawback: when I exit putty, I can no longer ssh to the server! In other words, when I try to ssh to the server as root, it immediately kicks me out and doesn't allow me to login, and that's why I had to reinstall the server. How can I solve this problem?
Note: I am very new to the Linux server world, so please explain your solution in a simple manner.