Wednesday, November 8, 2017

linux - Forced per-user ssh port



I want to allow access to each user on a server through a different port. For example; user1 can only be accessed by ssh through port 2201, user 2 can only be accessed through port 2202. I have already allowed access through ports 2201 and 2202 by editing "/etc/ssh/sshd_config" and adding two lines:




Port 2201
Port 2202




Both users can now access ssh through both ports (and 22).




  • How would I restrict them to only their own ports?



(Also), the users [except root] don't have any automatically created "~/.ssh/" directory so I made one and tried adding a config file and an authorized_keys file - these don't seem to make any difference.



OS is debian squeeze and thanks in advance.


Answer




You'll have to create a separate sshd_config for each user/port combo containing (along with the usual configuration options) the ListenAddress and AllowUsers keywords.



sshd_config_2201



ListenAddress 0:2201
AllowUsers user1


sshd_config_2202




ListenAddress 0:2202
AllowUsers user2


etc.



You'll need to run sshd once for each user with the -f switch to specify the individual configuration files.


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...