jcanfield
12/11/2014 - 5:47 PM

Giving new users SSH access

Giving new users SSH access

# 1. Start by ssh-ing into the server
ssh opportunity.org # or whatever server you need to access

# 2. Once in the server add a user with whatever username you'd like. You must use the sudo command unless you're logged in as root.
sudo adduser {username}
sudo adduser {username} sudo # to add user to sudo group

# 3. Change into the new users directory. /home contains all the users on the system.
cd /home/{username}

# 4. Create a new directory for the ssh key and cd into the direcoty. If it won't create the directory, run with sudo.
mkdir .ssh; cd .ssh

# 5. Create an authorized_keys file, then paste in their public key and save the file.
nano authorized_keys # paste once in nano

# 6. Change the authorized_keys file permissions
sudo chmod 600 authorized_keys

# 7. Move up back to the home directory and change the ssh directory file permissions
cd ..
sudo chmod 700 .ssh

# 8. Check that the .ssh/ directory and the authorized_keys file are owned by {username}
# If it isn't (it might be owned by root since you used sudo), those will need to change as well.
# You can do it with one command, recusively for all files under the ssh directory like so
sudo chown -R {username}:{username} .ssh

# 9. Update the sshd config file and add the new user to the AllowUsers line 
sudo nano /etc/ssh/sshd_config

# 10. Restart the ssh daemon
sudo service ssh restart