ssh_exchange_identification:连接被远程主机关闭

4 linux ssh

第一的:

$ ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa
$ cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
Run Code Online (Sandbox Code Playgroud)

连接到 SSH 服务器会显示以下消息:

$ ssh -vvv localhost
OpenSSH_5.3p1, OpenSSL 0.9.8m 25 Feb 2010
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to localhost [127.0.0.1] port 22.
debug1: Connection established.
debug1: identity file /home/charlie/.ssh/identity type -1
debug1: identity file /home/charlie/.ssh/id_rsa type -1
debug3: Not a RSA1 key file /home/charlie/.ssh/id_dsa.
debug2: key_type_from_name: unknown key type '-----BEGIN'
debug3: key_read: missing keytype
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug2: key_type_from_name: unknown key type '-----END'
debug3: key_read: missing keytype
debug1: identity file /home/charlie/.ssh/id_dsa type 2
ssh_exchange_identification: Connection closed by remote host
Run Code Online (Sandbox Code Playgroud)

我的 /etc/hosts.allow 如下:

sshd: ALLOW
Run Code Online (Sandbox Code Playgroud)

/etc/hosts.deny 如下:

ALL: ALL: DENY
Run Code Online (Sandbox Code Playgroud)

我已经改变了我的 /etc/ssh/sshd_conf 如下:

ListenAddress 0.0.0.0
Protocol 2

# HostKey for protocol version 1
#HostKey /etc/ssh/ssh_host_key
# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key


RSAAuthentication yes
PubkeyAuthentication yes
#AuthorizedKeysFile     .ssh/authorized_keys

PasswordAuthentication no
Run Code Online (Sandbox Code Playgroud)

jdi*_*zle 6

仔细检查您的.ssh目录和.ssh/authorized_keys文件上的权限。那些需要被chmod 700600分别。