Setting up private / public key authentication, a quick guide

# On your own computer (client machine), go to the .ssh folder of your home and generate the key

cd ~/.ssh
ssh-keygen -b 2048 -t rsa => enter a passphrase (nice to have)

# Copy the new public key to the server
# many systems especially macs don’t have ssh-copy-id
# and scp may overwrite previous content of authorized_keys on server
cat ./id_rsa.pub | ssh you@hostname.com “cat >>~/.ssh/authorized_keys”

# Go onto the server, you will still need to enter a password here
# Make sure that the key and .ssh folder on the server is secure enough
# Many ssh client will not let you through if the permission is too open
cd ~/
chmod 700 .ssh
=> the result of “ls -latrh | grep .ssh” should be “drwx——. 2 you you 4.0K May 29 16:21 .ssh”
cd ~/.ssh
chmod 600 authorized_keys
=> the result of “ls -latrh | grep authorized_keys” should be “-rw——-. 1 you you 400 May 29 16:31 authorized_keys

# Logout, you are done! The next time you log in again you will not need a password.
exit

Leave a Reply

Your email address will not be published.