SSH Tips to improve workflow

For the forgetful like me.

SSH keys

I find logging in with my password after logging into a password protected computer each time a pain. To get around this, I set up an SSH key to identify my computer uniquely. This requires some basic bash scripting. Can be done with windows with puTTy.

Note I will be using the term local to represent the computer you are using, and remote to represent the computer you are connecting to.

  1. Open terminal. use ssh-keygen -t rsa and follow the prompts. A passphrase can be used, but it creates the same redundant scenario where I need to log in so I leave this as blank. choose wherever you want to store the file. For the sake of this I’m assuming that its in the same folder you’re working from.

Now, we have both a public and private key that has been generated (by default this is id_rsa, but it can be whatever you want to call it). We need to pass the public key (id_rsa.pub) to wherever we want to SSH to. Keep the private key SAFE and do not share it.

  1. To do this quickly, you can use ssh-copy-id user@serverlogin.ca however this assumes that there is a hidden folder (any file/folder with a . at the start of the file name is considered hidden) named "~/.ssh/authorized_keys". if you used the quick method, you will be given a warning asking if you’re sure (say yes) and enter your password. if this fails, you will have to login to your remote and create the .ssh/authorized_keys folders.

  2. Back on your local machine, you are ready to ssh without using a password ever again. all you need to do is run the following code:

ssh -i id_rsa user@serverlogin.ca where id_rsa is the private key. to go a step further, you can create a bash script with this code alone by running something even simpler like bash login.sh and call it a day.