sshd 在 lxc(ubuntu)中不起作用(但已启动)

sshd 在 lxc(ubuntu)中不起作用(但已启动)

当我尝试连接时,它会失败,并且我只能使用 连接到容器。ssh [email protected].*Read from socket failed: Connection reset by peerlxc-attach -n (name)

我怎样才能解决这个问题?

更新 0:

$ ssh -vvv [email protected]
OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to 10.0.0.243 [10.0.0.243] port 22.
debug1: Connection established.
debug1: identity file /home/guava/.ssh/id_rsa type -1
debug1: identity file /home/guava/.ssh/id_rsa-cert type -1
debug1: identity file /home/guava/.ssh/id_dsa type -1
debug1: identity file /home/guava/.ssh/id_dsa-cert type -1
debug1: identity file /home/guava/.ssh/id_ecdsa type -1
debug1: identity file /home/guava/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/guava/.ssh/id_ed25519 type -1
debug1: identity file /home/guava/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.3
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.3
debug1: match: OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.3 pat OpenSSH_6.6.1* compat 0x04000000
debug2: fd 3 setting O_NONBLOCK
debug3: load_hostkeys: loading entries for host "10.0.0.243" from file "/home/guava/.ssh/known_hosts"
debug3: load_hostkeys: loaded 0 keys
debug1: SSH2_MSG_KEXINIT sent
Read from socket failed: Connection reset by peer

答案1

您可以尝试将详细的 svitch 添加到 ssd 命令以进行调试:

ssh -vvv [email protected]

-v - 代表详细,可以添加多个选项,最大为 3 个

更新0

权限设置正确吗?

sudo chmod 644 ~/.ssh/known_hosts
sudo chmod 755 ~/.ssh
sudo chmod 600 ~/.ssh/id_rsa
sudo chmod 600 ~/.ssh/id_rsa.pub

在远程主机上:

sudo chmod 600 /etc/ssh/ssh_host_*

两台机器的时间是否同步?

更新 1

您能将 tail 放在远程机器的 auth.log 上吗?

tail -500 /var/log/auth.log | grep 'sshd'

/etc/ssh/sshd_configlog_level DEBUG/INFO 中:

SyslogFacility AUTH
LogLevel INFO

答案2

这个问题已经存在好久了,但是这里没有针对 LXC 的答案。

如果主机将 sshd 绑定到 0.0.0.0:22,则主机上的 sshd 占用了所有接口,因此容器中的 sshd 无法获取空闲接口。必须将主机上的 sshd 配置为不是监听所有接口,/etc/ssh/sshd_config因此

ListenAddress 0.0.0.0

必须替换为

ListenAddress 192.168.0.55

如果网络接口的 IP 地址是 192.168.0.55(将其更改为网络接口的 IP 地址)。

相关内容