SSH远程连接报错:Permission denied, please try again.的解决办法备忘

Posted Herotwins

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SSH远程连接报错:Permission denied, please try again.的解决办法备忘相关的知识,希望对你有一定的参考价值。

问题描述

当使用 SSH 登录Linux 服务器时,如果是 root 用户,即便正确输入密码,也会出现如下错误信息“Permission denied, please try again.”

但非root用户可以正常登录。

问题原因

服务端SSH 服务配置了禁止root用户登录策略。

处理办法

要解决此问题,请进行如下配置检查和修改:

1、进入系统。

2、通过 cat /etc/ssh/sshd_config 查看是否包含类似如下配置:

PermitRootLogin no

若是no,需要修改成yes

PermitRootLogin yes

3、修改后重启 SSH 服务:

service sshd restart

4、尝试再次使用 root 用户登录服务器,登录成功。

git连接报错:Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password)

  在Linux上已经安装过git了,本机(windows)想连接,通过git bash敲了下clone命令提示没权限:

$ git clone [email protected]111.11.111.11:code.git
Cloning into code...
The authenticity of host 111.11.111.11 (111.11.111.11) cant be established.
ECDSA key fingerprint is SHA256:7jmL7Nrr9zJ7psJd3Zcfr4UckRNOMkgwK/ae9dsCgaw.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 116.62.136.56 (ECDSA) to the list of known hosts.
[email protected]111.11.111.11s password:
Connection closed by 111.11.111.11 port 22
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

  第一次连接失败很正常,毕竟没有设置账号信息,但第二次连接敲了自己刚设置的密码,竟然一直提示没权限

$ git clone [email protected]111.11.111.11:code.git
Cloning into code...
[email protected]111.11.111.11s password:
Permission denied, please try again.
[email protected]111.11.111.11s password:
Permission denied, please try again.
[email protected]111.11.111.11s password:
[email protected]111.11.111.11: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,pas                                                                                                                sword).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

  蒙圈了,密码对的啊。看下日志:

$ ssh -vT [email protected]111.11.111.11
OpenSSH_7.6p1, OpenSSL 1.0.2n  7 Dec 2017
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to 111.11.111.11 [111.11.111.11] port 22.
debug1: Connection established.
debug1: identity file /c/Users/wulf/.ssh/id_rsa type 0
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/wulf/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/wulf/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/wulf/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/wulf/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/wulf/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/wulf/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/wulf/.ssh/id_ed25519-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.6
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4
debug1: match: OpenSSH_7.4 pat OpenSSH* compat 0x04000000
debug1: Authenticating to 111.11.111.11:22 as git
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: aes128-ctr MAC: umac-64-[email protected] comp                                                                                                                ression: none
debug1: kex: client->server cipher: aes128-ctr MAC: umac-64-[email protected] comp                                                                                                                ression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:7jmL7Nrr9zJ7psJd3Zcfr4UckRNO                                                                                                                MkgwK/ae9dsCgaw
debug1: Host 111.11.111.11 is known and matches the ECDSA host key.
debug1: Found key in /c/Users/wulf/.ssh/known_hosts:14
debug1: rekey after 4294967296 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 4294967296 blocks
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mi                                                                                                                c,password
debug1: Next authentication method: publickey
debug1: Offering public key: RSA SHA256:gXnx5odoFP7yK+Imse/ggjIzZdFZBmJwCU6T6PEy                                                                                                                spk /c/Users/wulf/.ssh/id_rsa
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mi                                                                                                                c,password
debug1: Trying private key: /c/Users/wulf/.ssh/id_dsa
debug1: Trying private key: /c/Users/wulf/.ssh/id_ecdsa
debug1: Trying private key: /c/Users/wulf/.ssh/id_ed25519
debug1: Next authentication method: password

  接着看一下我的公钥:

$ cat /c/Users/wulf/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCf20s0rabgMRn8CCCCC/+VC/wS5x/dvIYoG+TP23bHWn9gD/AXizrkds5geX9AG90oVRqf+RfTvLFlaNMrzK

  公钥太长,随便贴了点。后来才发现linux上的git根本不认识你,因为你有的是你自己的密码,人家那还没有你的公钥呢,得去它那里设置一下。

  登陆linux下的111.11.111.11,把上面那段公钥丢到authorized_keys里:

vi /home/git/.ssh/authorized_keys

  保存后再去本地连下,ok了:

$ git clone [email protected]111.11.111.11:code.git
Cloning into code...
warning: You appear to have cloned an empty repository.

 

 

---恢复内容结束---

以上是关于SSH远程连接报错:Permission denied, please try again.的解决办法备忘的主要内容,如果未能解决你的问题,请参考以下文章

git连接报错:Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password)

关于SSH远程连接报错

scp传输出现ssh服务连接报错

ssh连接报错解决

ssh远程连接报错ssh_exchange_identification: Connection closed by remote host

ArcCatalog连接ArcSDE连接报:unable to create new database connection file,permission is denied