What are SSH keys:
SSH key is a more secure alternative to passwords for logging into your machine.
With SSH you will have two keys, one .pub key, and a private key and the idea is you will store the .pub key in your server and the private key in your local machine, after doing this you can just ssh into your server without the need of the password. it is more secure since it is key-based authentication.
To generate SSH Keys:
ssh-keygen
This will ask you where you wish to save your keys, it should be in the .ssh directory, the default is usually a good choice, but you can specify a path if you wish by giving it a path when you are prompted to do so.
This will generate two keys in the directory you specified.
1.key
2.key.pub
Installing the public key:
In order to be able to log into your server using SSH, first, you need to copy your .pub key into your server.
To do this:
mkdir .ssh
touch .ssh/authorized_keys
Now if you have done everything correctly you should be able to log into your server using ssh.
e.g let's say we have a user called "student" and our private key which we generated above using ssh-keygen method is stored in ~/.ssh/private_key
~ is a short cut for the home directory or C/user/username/ in windows.
ssh student@127.0.0.1 -p 2200 -i ~/.ssh/private_key
You can always log into your server using a different pair of keys, as long as the server has the pub key and your local machine/mobile has the private.
It goes without saying .pub key and the private key are pair and only work with each other, you can not use a private key generated in one occasion to a public key generated on a different occasion.
{% url 'home' %}