ssh-keygen -t rsa
Once you have entered the Gen Key command, you will get a few more questions:
Enter file in which to save the key (/home/demo/.ssh/id_rsa):
You can press enter here, saving the file to the user home (in this case, my example user is called demo).
Enter passphrase (empty for no passphrase):
It's up to you whether you want to use a passphrase. Entering a passphrase does have its benefits: the security of a key, no matter how encrypted, still depends on the fact that it is not visible to anyone else. Should a passphrase-protected private key fall into an unauthorized users possession, they will be unable to log in to its associated accounts until they figure out the passphrase, buying the hacked user some extra time. The only downside, of course, to having a passphrase, is then having to type it in each time you use the Key Pair.
Once the key pair is generated, it's time to place the public key on the virtual server that we want to use.
You can copy the public key into the new machine's authorized_keys file with the ssh-copy-id command. Make sure to replace the example username and IP address below.
ssh-copy-id user@123.45.56.78
curl -L https://raw.githubusercontent.com/beautifulcode/ssh-copy-id-for-OSX/master/install.sh | sh
Or clone from https://github.com/beautifulcode/ssh-copy-id-for-OSX.
Now you can connect to your server without a password and that’s great. But it can be a drag to remember username or port or even domain name so let’s dumb it down a little bit more.
First step is to position yourself to .ssh directory.
cd ~/.ssh
If you were to type in the “ls” command you’d see that directory is populated with generated private and public keys. To move to the next step we have to create a config file. You can do it with vim, nano or something else. There are numerous ways to do it. Use whichever editor you’re most comfortable with.
vim config
Fill the config file with following lines:
Host myServer
HostName yourserver.com # Or IP
User yourusername
IdentityFile ~/.ssh/id_rsa
:)
- Implement tunnels
- How to handle downloaded keys
- Create setup steps