如何在同一台机器上从 Windows SSH 到 WSL

Bas*_*nem 69 ssh bash windows-10 windows-subsystem-for-linux

长期读者,第一次提问。

我按照此答案中的说明进行操作:

如何通过 SSH 连接到“Windows 10 上的 Ubuntu 上的 Bash”?

我正在尝试在同一台机器上的 Windows 中从 PuTTY 进行 SSH。使用与我的配置文件匹配的端口 22。尝试了 127.0.0.1 和 127.0.1.1。但是,我仍然收到“拒绝访问”的消息:

在此处输入图片说明

最终我希望建立一个 Visual Studio 远程构建,但到目前为止我根本无法远程进入。我应该采取哪些后续步骤?

Process Hacker 为端口 22 显示了这一点(不确定这意味着什么):

在此处输入图片说明

以下是 /etc/ssh/sshd_config 的内容:

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

# What ports, IPs and protocols we listen for
Port 22
# 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
HostKey /etc/ssh/ssh_host_ed25519_key
#Privilege Separation is turned on for security
UsePrivilegeSeparation no

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

# Logging
SyslogFacility AUTH
LogLevel INFO

# Authentication:
LoginGraceTime 120
PermitRootLogin no
AllowUsers basel
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
Run Code Online (Sandbox Code Playgroud)

小智 45

把文件里的22端口改成其他的,比如2222,/etc/ssh/sshd_config然后用sudo service ssh --full-restartcommond重启ssh服务,就可以登录成功了,不知道是什么原因。

我也尝试将其用作 VisualGDB 的 Visual Studio 的远程 gdb 服务器,但效果不佳。VisualGDB 将在下个版本支持,如官网所示。链接为https://sysprogs.com/w/forums/topic/visualgdb-with-windows-10-anniversary-update-linux-support/#post- 9274

  • 可能,您还需要更改身份验证。默认情况下,它需要客户端的 ssh 密钥。如果你想要经典的用户/密码登录,在`/etc/ssh/sshd_config`中设置这个配置:`PubkeyAuthentication no PasswordAuthentication yes` (6认同)
  • 这是因为 Windows 可能会在端口 22 上运行 SSH Server Broker。除非您确定需要它,否则可以安全地禁用它。它用于开发过程中的某些程序。 (4认同)
  • 不要忘记在 Windows 防火墙中打开端口。 (4认同)

小智 40

端口 22 不起作用,因为 Windows 带有内置的 SSH 服务器。

Windows 10 带有一个 SSH 服务器,它要么需要被禁用,要么需要更改用于 WSL 上的 SSH 的端口。我选择了后者,并为 WSL SSH 使用端口 2200。

来源:https : //virtualizationreview.com/articles/2017/02/08/graphical-programs-on-windows-subsystem-on-linux.aspx

  • 这实际上是这个问题的唯一正确答案,即使是公认的答案,也暗示这是必须更改端口的原因。我将在 24 小时内奖励这个答案。 (2认同)