Setup SSH Key in Linux
About SSH Key
SSH keys provide a more secure way of logging into a virtual private server with SSH than using a password alone. While a password can eventually be cracked with a brute force attack, SSH keys are nearly impossible to decipher by brute force alone. Generating a key pair provides you with two long string of characters: a public and a private key. You can place the public key on any server, and then unlock it by connecting to it with a client that already has the private key. When the two match up, the system unlocks without the need for a password. You can increase security even more by protecting the private key with a passphrase.
Create SSH Key for User in Linux
The first step is to create the key pair on the client machine (there is a good chance that this will just be your computer) using below script.
$ ssh-keygen -t rsa
Once you have entered the Gen Key command, you will get a few more questions. Just answer it with enter, enter, and enter until it end. Then from your home directory, the key location will be in
$ cd /home/[user]/.ssh
From here, we can create file authorized_keys to put other public keys. And change the permission to make the file can be read and write by user only.
$ vi authorized_keys $ chmod go-rw authorized_keys
Set Other Public Key to Make It Can Access Your Machine Automatically
Put othert public keys in authorized_keys. And make sure the public key put there without space. Find below example :
$ vi authorized_keys [put the public key here without space]
Then this user can access the machine automatically.