-
Notifications
You must be signed in to change notification settings - Fork 15
Access to Server via SSH
There are several ways to generate an rsa key pair, or you can use an existing one.
- The GitHub way:
-
Create a new ssh key, using your email as a label
ssh-keygen -t rsa -b 4096 -C "[email protected]" # generating public/private rsa key pair.
-
When you're prompted to
Enter a file in which to save the key
, press Enter. This accepts the default file location. -
At the
Enter passphrase (empty for no passphrase)
prompt, type a secure passphrase. A passphrase is a long word to identify your rsa key. It is okay to leave it blank and hit Enter. -
Before adding a new SSH key to the ssh-agent, you should have checked for existing SSH keys and generated a new SSH key.
eval "$(ssh-agent -s)" # start the ssh-agent in the background
-
Add your SSH key to the ssh-agent.
ssh-add ~/.ssh/id_rsa
- Use an Existing Key Pair
-
Go to Terminal, type
cd ~/.ssh
and look for the pair of files that have the same name name but different extensions, eg.id_rsa
andid_rsa.pub
. They are your private key and public key. -
Keep the private key untouched, and copy the public key as a file to your Server.
-
NOTE: Be sure to use the original .pub file instead of doing copy-paste keys!!
-
Copy your public key and rename it to
authorized_keys
under hidden folder.ssh
.mkdir .ssh # skip this step if you already have it in your home directory chmod 700 .ssh # change the permission of folder .ssh cd .ssh touch authorized_keys chmod 600 authorized_keys # change the permission of file cat id_rsa.pub >> authorized_keys # concatenate id_rsa.pub to authorized_keys
-
Change user authorization
-
Go to Terminal:
cd /etc/ssh/ sudo vim sshd_config
-
On Line 90, add user to Allowusers
-
Restart ssh to make changes valid
sudo service sshd restart
- On Client, go to Terminal:
ssh -1 -v username@hostIP
Or ssh -v -i ~/.ssh/id_rsa username@hostIP
to indicate the location of key.
- The next screen you will be on the Server!
-
GitHub: Generate a New SSH Key:
[https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/])
-
Ubuntu help: SSH/OpenSSH/Keys:
[https://help.ubuntu.com/community/SSH/OpenSSH/Keys]