Create the new public and private keys, then rename and copy and delete the public key:
ssh-keygen cd ~/.ssh/ cp id_rsa.pub authorized_keys rm -rf id_rsa.pub
Copy the key cat id_rsa
to your computer and then deleterm -rf id_rsa
. Only with this key will you have access to the server.
The setting below is to extend bash's auto-complete functions.
sudo nano /etc/bash.bashrc
# enable bash completion in interactive shells if ! shopt -oq posix; then if [ -f /usr/share/bash-completion/bash_completion ]; then . /usr/share/bash-completion/bash_completion elif [ -f /etc/bash_completion ]; then . /etc/bash_completion fi fi
sudo reboot
sudo nano /etc/ssh/sshd_config
Look for the “PasswordAuthentication” section in this configuration file, and change its value to “No”.
PasswordAuthentication no
Ready! Once the server restarts you will only have access with the private key.
Before you start working, update the packages to the latest versions.
sudo apt update; sudo apt upgrade -y
Bonus: install htop for an extended version of the top, sl to liven up your life and ncdu for disk space analysis
sudo apt install htop sl ncdu -y