Troubleshoot ssh "Permission denied" error

If you see a permission error like below when you ssh into a host, the public key may not be set on the remote host.

tomo@192.168.11.8: Permission denied (publickey,gssapi-keyex,gssapi-with-mic). 

assumption

Assume that you are trying to ssh into a host at 192.168.11.8 and the user (tomo) is already created.

ref: https://web-quickstart.blogspot.com/2021/03/vagrant.html

$ vim Vagrantfile
Vagrant.configure("2") do |config|
  config.vm.box = "centos/7"
  config.vm.hostname = 'myhost'
  config.vm.network "private_network", ip: "192.168.11.8"
end
$ vagrant up
$ vagrant ssh -c 'sudo adduser tomo'


1. generate key on client

First, check if you have a public key and private key on the client side.

$ ls ~/.ssh/

If not found, then create them by running:

$ ssh-keygen
...

$ ls ~/.ssh/
id_rsa
id_rsa.pub

2. add public key on server

Add the id_rsa.pub onto the remote host under user's home:

$ sudo mkdir /home/tomo/.ssh
$ sudo vi /home/tomo/.ssh/authorized_keys # paste value of id_rsa.pub


3. try again

You can try again to see if the error is gone:

$ ssh tomo@192.168.11.8


Comments

Popular posts from this blog

Selenide: Quick Start

Minikube Installation for M1 Mac

Three.js Quick Start - Run Spinning-Cube Example