Unable to ssh localhost: Permission denied (publickey) / Connection closed by ::1 [preauth]
After reading some good manuals I realized that the public key of ubuntu@ (e.g., /home/ubuntu/.ssh/id_dsa.pub) must be added to the user's /home/ubuntu/.ssh/authorized_keys file, which contains public keys for public key authentication)
ubuntu@<localhost>:~$ cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
If you're running Ubuntu on Windows Subsystem for Linux, there will not be a preinstalled public key or authorized keys list, so you'll need to generate your own.
If you don't already have openssh-server installed:
sudo apt-get upgrade
sudo apt-get update
sudo apt-get install openssh-server
sudo service ssh start
Then take the following steps to enable ssh
ing to localhost:
cd ~/.ssh
ssh-keygen
to generate a public/private rsa key pair; use the default optionscat id_rsa.pub >> authorized_keys
to append the key to the authorized_keys filechmod 640 authorized_keys
to set restricted permissionssudo service ssh restart
to pickup recent changesssh localhost