If you go ahead and try your new alias, you will see hey with one short command I can connect to lab46, but darn it I still have to type that annoying little password, I don't want to do that! Well pay close attention boys and girls.
Make sure you are in your home directory, first we are going to generate a “Key”, so type:
ssh-keygen -t rsa
This is going to ask you where to store the key file, use the default.
It will also ask you for a passphrase which you can do but I chose not
If you look at the newly created .ssh directory and its contents you will see two files. id_rsa and id_rsa.pub, this is two key files, one is private and one is public. The public one is what you give to other hosts so it can check your private key and recognize who you are!
Now that we have created a key on our primary machine we now want to copy the public key, aka id_rsa.pub, to the host machine.
Go ahead and log into lab46 and type in that annoying password this time. Once you are logged in type the following:
scp user@primarymachine:~/.ssh/id_rsa.pub ~/.ssh/
user@primarymachine being your home machine, for testing I used my virtual server so used “root@vmserver05.student.lab”
You will be prompted for the password, remember its for your home machine at this point because you are logged into lab46.
You have now copied the file with your primary machines public key into the host machine.
cd into .ssh on lab46 and type:
cat id_rsa.pub » ~/.ssh/authorized_keys
What you have done here has copied your primary machines public key from the .pub file into an authorized_keys file.
The reason I had you append is just in case you have multiple machines with keys, you do not want to overwrite them.