Create the pair of your key on your local machine.
$ mkdir -m 700 ~/.ssh
$ ssh-keygen
$ chmod 600 ~/.ssh/id_rsa ~/.ssh/id_rsa.pub
$ cat ~/.ssh/id_rsa.pub
Setting your public key on your remote machine.
$ mkdir -m 700 ~/.ssh
$ echo "<your public key>" ~/.ssh/authorized_keys
$ chmod 600 ~/.ssh/authorized_keys
Start other terminal on local machine and test public key based authorization.
$ ssh <remote hostname>
Edit /etc/ssh/sshd_config
.
$ sudo vi /etc/ssh/sshd_config
Off to login by root
user.
PermitRootLogin no
Off to login based input password.
PasswordAuthentication no
Check configuration.
$ sudo sshd -t
Restart sshd
.
$ sudo service ssh restart
Check ufw
status.
$ sudo ufw status
Status: inactive
Switch deny for all ports.
$ sudo ufw default deny
Open the only port for SSH.
$ sudo ufw allow 22
Switch ufw
to enable.
$ sudo ufw enable
Check ufw
status.
$ sudo ufw status
Status: active
To Action From
-- ------ ----
22 ALLOW Anywhere
22 ALLOW Anywhere (v6)
$ sudo apt-get update
$ sudo apt-get upgrade