Setting up SSH keys

These are not completely tested. They should work though. Pay attention to spacing and quotes.

First, generate new SSH keys. Use a good passphrase. Follow the instructions. If you want to use 8192 for the key size, you can substitute that.

ssh-keygen -t rsa -b 4096

Next, start ssh-agent and give it your new key. Later, you may want to set ssh-agent to start automatically.

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa

Transmit ONLY the public key to the server you want to log into. You can also use ssh-copy-id if you have it, but this method doesn't require installing anything else. You may have to mkdir ~/.ssh on the server if it doesn't already exist.

cat ~/.ssh/id_rsa.pub | ssh -p [port] [user]@[server] 'cat - >> ~/.ssh/authorized_keys'

Make sure the permissions on the remote system are properly set.

ssh -p [port] [user]@[server] 'chmod 700 ~/.ssh; chmod 600 ~/.ssh/authorized_keys'

Now log in. You may be asked for a password by ssh-agent the first time you log in, but after that you should not be required to enter your password.

ssh -p [port] [user]@[server]

If you are going to log into any servers inside (such as a virtual machine) you can copy your authorized keys to that internal server.

cat ~/.ssh/authorized_keys | ssh -p [port] [user]@[vm] 'cat - >> ~/.ssh/authorized_keys'

When you log into the main server and try to log into the virtual machine, you'll still be asked for your password. You need to use the -A option when logging into the main server to forward the ssh-agent connection.

ssh -A -p [port] [user]@[server]

Then, you can log into the internal server. You don't need the -A option there unless you plan to hop to yet another server.