Permission denied (publickey,gssapi-keyex,gssapi-with-mic) solution

Background: A
new virtual machine was created on google cloud before. Later, because the path "~/.ssh/authorized_keys" was manually modified, the above error occurred: Permission denied (publickey,gssapi-keyex,gssapi-with -mic). I follow my usual style and directly google the error message. Do not think about possible problems at all. But it can also explain, one of the reasons why I did this was that it was late at the time. I tried to modify the sshd_config file but it didn’t work, and I changed multiple values ​​many times, but there was no control variable and no work, so I thought I was modifying the configuration. The "PasswordAuthentication" field is no operation. It's still useful to take a Google search problem to calm down, but it's really not helpful to face a full screen of English when you are impetuous. Finally, this problem was solved with the help of Brother Cao.

Body:
In fact, when the error Permission denied (publickey, gssapi-keyex, gssapi-with-mic) appears, we may be fortunate that this error indicates that the firewall on our cloud platform and the sshd service of the virtual machine are good. It's just that there are some problems with our configuration.
The publickey Permission denied error message in this error actually tells us that our public key is wrong. Under normal circumstances, we can understand this problem and solve the problem quickly. Put the public key on the server ~/.ssh/ Can be in the authorized_keys file. But after trying "ssh centos@ip", I get this error and I get a little confused, especially for my side dishes. I haven't met it before, so I don't know, but after experimenting, I realized that this is because the field of PasswordAuthentication is "no".
So encountering this kind of problem is to modify

sudo vim /etc/ssh/sshd_config
增加如下修改
PasswordAuthentication yes


sudo systemctl restart sshd

or

sudo  ~/ssh/authorized_keys
添加你本机的公钥到该文件中

Note:
If you prefer to log in as a root user, make sure

/etc/ssh/sshd_config

PermitRootLogin yes

Modify it to PermitRootLogin yes, modify it to PubkeyAuthentication yes (if there is # before it, remove #)

service sshd restart restarts the sshd service and connects again.

Guess you like

Origin blog.csdn.net/qq_29528701/article/details/103240793