Linux (28) Python (13) Raspberry Pi (5) Bugs (3) Install (3) C (2) Brainf**k (1) HTML (1) Maths (1) Sorts (1)

Friday, 31 July 2015

How to only allow specific users SSH access

This post shows you to set the users that are allow SSH access.
If you don't have SSH installed then run
On Ubuntu/Debian/Mint
sudo apt-get install openssh-client openssh-server
On RHEL/Fedora/Centos
sudo yum -y install openssh-clients openssh-server

To make things easier login with root using su - as most of the commands need root privileges.
Or you can just put sudo in front of all of these commands.
Firstly make a backup of the file we will be working with in case you want to return to your original setup.
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak

The line we are going to add to the file is AllowUsers "Put users here separated by spaces"

So add the line and then after it a comment for future reference something like only allow SSH access with these users

Now we need to restart the sshd service
If you are running Ubuntu/Debian/Mint run
service ssh restart
If you are running RHEL/Fedora/Centos
service sshd restart

If you are currently logged in over ssh this will close the connection and a new one will be created.

Now if you try and login with a user not specified in the sshd config file
ssh "blocked user"@"ip of pc"
You will not be able to
But if you try to login with a user specified in the sshd config file
ssh "specified user"@"ip of pc"
You should be able to login as usual.

No comments:

Post a comment