Last active
March 31, 2018 22:41
-
-
Save wosephjeber/5fff5f59363fabefce4e to your computer and use it in GitHub Desktop.
Giving new users SSH access
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment