简体   繁体   中英

Unable to connect via ssh with public key authentication method

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 lauser@127.0.0.1 -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.

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 .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM