Use SSH Like a Pro

Using SSH Like a pro

First we will need to generate our ssh keys on our local machine for this we use

ssh-keygen -t ed25519  -b 4096

you will be prompted to save these keys you should just press enter and accepts the defaults, You will now be asked to provide a passphase to protect the key, I think it's good practise to do this but the choice is yours.

Now we have our ssh keys we can use them to logging securely to other machines but first we will have to check the setup on the other machines to make sure they are able to accept public key authentication.

We login to our machine

ssh root@remote-machine

touch .ssh/authorized_keys

touch .ssh/known_hosts

now we are ready to have a look and the sshd_config file located

/etc/ssh/sshd_config we will run

nano /etc/ssh/sshd_config

the Lines we are interested in

#Port 22

#PubkeyAuthentication yes

#AuthorizedKeysFile      .ssh/authorized_keys .ssh/authorized_keys2

remove the hash symbol from these line and save and exit the file.

At this point whilst still connected with your current ssh session open a new terminal and type the following on you local machine.

ssh-copy-id root@remote-machine

this will copy your local ssh public key to to remote server.

Now back to the remote machine will restart the ssh service so the changes we made will take effect with.

service ssh restart

At this point whilst still connected with your current ssh session open a new terminal and try to login if your able to login your done.

and logging again if you can login without a password every thing worked correctly and if it didn't you still have the other ssh session connected to revert the changes.