简体   繁体   English

无法使用 Ngrok SSH 到 Windows 机器

[英]Unable to SSH to a Windows machine using Ngrok

I'm trying to connect to Windows user through SSH (public key authentication) from a remote machine over the internet using ngrok.我正在尝试使用 ngrok 从互联网上的远程计算机通过 SSH (公钥身份验证)连接到 Windows 用户。 But apparently not working.但显然不起作用。

Here are what I have done.这是我所做的。

I installed and activated the SSH on the windows.我在 windows 上安装并激活了 SSH。

Get-WindowsCapability -Online | ? Name -like 'OpenSSH*'
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0

I generated public key files and sent to the remote machine to ssh from.我生成了公钥文件并从远程机器发送到 ssh。

ssh-keygen

I changed/added following lines in the SSH setting file "C:\ProgramData\ssh\sshd_config"我在 SSH 设置文件“C:\ProgramData\ssh\sshd_config”中更改/添加了以下行

PermitRootLogin yes
AllowUsers otheruser
PubkeyAuthentication yes 
PasswordAuthentication no 

I restarted the ssh server to apply the setting changes.我重新启动了 ssh 服务器以应用设置更改。

net stop sshd ; net start sshd

I installed ngrok and run ngrok我安装了 ngrok 并运行 ngrok

./ngrok tcp 22
# got "6.tcp.ngrok.io:25252"

I tried to ssh from the remote machine to the windows machine, using the "tmp" secret key file to the user "tmp".我尝试将 ssh 从远程机器到 windows 机器,使用用户“tmp”的“tmp”密钥文件。

ssh -i "C:\pg\.ssh\tmp" tmp@6.tcp.ngrok.io -p 25252

and failed.并失败了。

ssh -i "C:\pg\.ssh\tmp" tmp@6.tcp.ngrok.io -p 25252
Enter passphrase for key 'C:\pg\.ssh\tmp':
tmp@6.tcp.ngrok.io: Permission denied (publickey,keyboard-interactive).

SSH to Windows is kind of waste of time. SSH 到 Windows 有点浪费时间。 Their document https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_keymanagement is outdated https://github.com/MicrosoftDocs/windowsserverdocs/issues/4598 and no longer works, unfortunately.他们的文档https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_keymanagement已过时https://github.com/MicrosoftDocs/windowsserverdocs/issues/4598并且不再有效。

If you're on Windows 10, I suggest using WSL Linux on your Windows 10. It's basically Linux machine on Windows, but also available for the SSH feature. If you're on Windows 10, I suggest using WSL Linux on your Windows 10. It's basically Linux machine on Windows, but also available for the SSH feature. The WSL SSHing does work perfectly as well as you can do on a Linux machine. WSL SSHing 可以完美运行,就像您在 Linux 机器上一样。

Not tested on Ngrok myself but have a try the following steps.本人未在 Ngrok 上进行测试,但请尝试以下步骤。

  • Install the features安装功能
Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH*'
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
  • Start the sshd server (optionally add the service to Automatic launch)启动 sshd 服务器(可选择将服务添加到自动启动)
Start-Service sshd
Set-Service -Name sshd -StartupType 'Automatic'
  • Add the below to C:\ProgramData\ssh\sshd_config (the path may be different)将以下内容添加到C:\ProgramData\ssh\sshd_config (路径可能不同)

Notice that StrictModes no .请注意, StrictModes no

PubkeyAuthentication yes
PasswordAuthentication no
StrictModes no
  • Add your client pub key(s) (or generate newly by ssh-keygen ) to the server's C:\ProgramData\ssh\administrators_authorized_keys and C:\Users\user\.ssh\authorized_keys将您的客户端发布密钥(或通过ssh-keygen新生成)添加到服务器的C:\ProgramData\ssh\administrators_authorized_keysC:\Users\user\.ssh\authorized_keys

Note that not only into authorized_keys but also into administrators_authorized_keys .请注意,不仅要进入authorized_keys ,还要进入administrators_authorized_keys Because if you're an admin on the server you need to have the authorized pub keys in the administrators_authorized_keys file specifically.因为如果您是服务器上的管理员,则需要在administrators_authorized_keys文件中专门拥有授权的 pub 密钥。 Adding the all pub keys to the both files doesn't hurt you.将所有 pub 密钥添加到这两个文件不会对您造成伤害。 (or edit the sshd_config file) (或编辑sshd_config文件)

  • Restart the sshd server重启 sshd 服务器

You must restart the server when its authorized_keys and/or sshd_config file is updated.当其 authorized_keys 和/或 sshd_config 文件更新时,您必须重新启动服务器。

stop-Service ssh
Start-Service sshd
  • SSH into SSH 进

Then try.然后尝试。

ssh user@192.168.1.2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM