如何让 SSH 服务器与 putty 客户端协同工作?

如何让 SSH 服务器与 putty 客户端协同工作?

我有一台 Ubuntu 12.04.01 台式电脑,64 位。它已openssh-server安装。

当我从 Linux 机器通过 SSH 连接到服务器时,它可以正常工作。但是当我从 Windows 7 PC 使用 PuTTY 进行连接时,我立即收到错误:

The server closed the connection unexpectidely

服务器和 PC 都位于同一个 LAN 上。两者都有静态 IP。

我搜索过但找不到 OpenSSH 服务器为什么会立即关闭连接。它甚至不提供登录选项。

请问我该如何找到并修复此问题?

编辑:sshd_config 文件内容添加:

# Package generated configuration file
# See the sshd_config(5) manpage for details

# What ports, IPs and protocols we listen for
# Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress ::
#ListenAddress 0.0.0.0
Protocol 2
# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
#Privilege Separation is turned on for security
UsePrivilegeSeparation yes

# Lifetime and size of ephemeral version 1 server key
KeyRegenerationInterval 3600
ServerKeyBits 768

# Logging
SyslogFacility AUTH
LogLevel INFO

# Authentication:
LoginGraceTime 120
PermitRootLogin yes
StrictModes yes

RSAAuthentication yes
PubkeyAuthentication yes
#AuthorizedKeysFile %h/.ssh/authorized_keys

# Don't read the user's ~/.rhosts and ~/.shosts files
IgnoreRhosts yes
# For this to work you will also need host keys in /etc/ssh_known_hosts
RhostsRSAAuthentication no
# similar for protocol version 2
HostbasedAuthentication no
# Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication
#IgnoreUserKnownHosts yes

# To enable empty passwords, change to yes (NOT RECOMMENDED)
PermitEmptyPasswords no

# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no

# Change to no to disable tunnelled clear text passwords
#PasswordAuthentication yes

# Kerberos options
#KerberosAuthentication no
#KerberosGetAFSToken no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes

X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
#UseLogin no

#MaxStartups 10:30:60
#Banner /etc/issue.net

# Allow client to pass locale environment variables
AcceptEnv LANG LC_*

Subsystem sftp /usr/lib/openssh/sftp-server

# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
UsePAM yes
IgnoreUserKnownHosts no
PasswordAuthentication yes
GatewayPorts yes
AllowTcpForwarding yes
KeepAlive yes

答案1

这听起来可能有点明显,但你需要为 ssh 设置 puTTY,它可以执行多种协议。在类别下会议

Hostname: <remote IP>
Connection Type: ssh
Port: <should default to 22>

请注意,如果您将端口从默认端口移开,那么您也必须在 Linux 连接中指定它。

类别中的下一个连接->SSH检查首选 SSH 是否设置为“2”或“仅 2”(您的配置显示两个支持,这是比 1 更好的选择)

最后,PuTTY 可以将信息存储在自己的日志中,这可能会阐明问题,请单击会话->日志记录类别来找出文件的位置,将日志记录设置为“所有会话输出”并查看显示的内容。

您收到的错误表明远程服务器甚至没有建立连接,这意味着:

  1. 您的 IP 错误
  2. 您输入了错误的端口
  3. 远程服务器上有防火墙阻止来自此框的连接
  4. 有一个 SSH 设置阻止您的特定主机连接(如 harish.venkat 所述)

答案2

在远程主机上,输入以下命令安装 open ssh 和 openssh-server

sudo apt-get 安装 openssh openssh-server

现在检查服务是否已启动,如果没有,则

sudo service ssh restart && sudo ps aux | grep ssh

如果连接仍然被阻止,则意味着您需要添加防火墙规则并重新启动防火墙

sudo service ufw enable ssh

sudo service ufw reload

将添加/启用 ssh 的防火墙规则。

确保检查 ssh 是否正在监听端口 22。要确认,请输入

sudo nmap -p22 localhost

现在尝试在你的 putty 或其他终端上执行 sshssh user@server-ip

希望这能有所帮助。祝你好运。

相关内容