Logbook.
SSH Keys May. 28 at 5:01 am
I frequently log in to various servers via SSH, and like to share an SSH key so I don’t need to type the password every time. Here’s a quick step by step for doing so from Mac OS 10.5 to an Ubuntu 9 server (so I don’t have to look for instructions anymore).
The idea is to create a key pair, one public and one private. The private key stays on your local system and the public key goes to the remote server(s). First, if you don’t already have a public/private key pair, create one on your Mac:
ssh-keygen
Follow the instructions to create an RSA pair, ~/.ssh/ is the default location. Copy the public key to your server (replace domain.tld with your server name, and /home/username with your home directory):
scp ~/.ssh/id_rsa.pub domain.tld:/home/username
Now you can SSH into your server…
ssh domain.tld
And check for an existing .ssh directory:
ls -al ~/
If it doesn’t exist, create it and make it private:
mkdir ~/.ssh
chmod 700 ~/.ssh
Move your public key to the ~/.ssh directory:
mv ~/id_rsa.pub ~/.ssh
Check if there’s an existing authorized_keys file:
ls -al ~/.ssh
If there isn’t you can simply rename your key and make it private:
mv ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
If you already had an ~/.ssh/authorized_keys file you can append your new key like so:
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
Now you should be able to exit the server and the next time you log in you won’t be prompted for a password. You can add your public key to the authorized_keys file of several servers.
Recent Entries
- Tide data for Canada Apr. 26 at 10:41 am
- Simple Referral Tracking Nov. 9 at 7:52 am
- Ruby HTML Indentation Jun. 27 at 9:47 am
- More logbook entries