1
votes

On my Windows 10, I am running into the problem of not being able to connect to m Vagrant virtual machine via ssh user with public key authentication method at git bash using command such as

$ ssh -v [email protected] -p 2222 -i ~/.ssh/id_rsa

I would be prompted for password, as if the public key I copied to in the ~/.ssh/Authorized_keys file inside the vm were not seen. Meanwhile,the password authentication method works, as well as 'vagrant ssh'. I have made sure to

  1. create key pairs locally, create a .ssh directory at the remote, and add pub key string to the remote's .ssh /authorized_keys file; both the .ssh and the .ssh /authorized_keys file are owned by the user(lauser), and set at 700 and 644

  2. edit the /etc/ssh/sshd_config file on vm to use RSAAuthentication yes PubkeyAuthentication yes and restarted the sshd server (with 'sudo service ssh restart').

  3. verify that firewall has been disabled temporarily to eliminate any complication.

  4. verify that there is only one vm running, all others are either in 'suspend' or 'halt' mode.

  5. confirm the file type by 'file ~/.ssh/authorized_keys', and get confirmation '~/.ssh/authorized_keys: OpenSSH RSA public key'

  6. verify that the keys match by comparing the output from 'sudo cat ~/.ssh/authorized_keys' in vm and the output from ' cat ~/.ssh/id_rsa.pub' at the local.

but still I get Permission denied (publickey) when trying to connect through public key authentication.

2
both ssh client and sshd server can tell you more. Run client in verbose mode to make sure it offers the key. If so, check server logs to see why it rejects your key.Jakuje
Thanks! How do I run " client in verbose mode" other than 'ssh -v'?Treefish Zhang

2 Answers

0
votes

It sounds like you've done everything correctly so far. When I run in to this problem, it's usually due to directory permissions on the target user's home directory (~), ~/.ssh or ~/.ssh/authorized_keys.

See this answer on SuperUser.

0
votes

I faced same challenges when the home directory on the remote did not have correct privileges. Changing permissions from 777 to 744 helped me