Joe*_*Joe 2 networking remote-desktop ssh
在我的家用 Windows 10 计算机上,我通过路由器将 Microsoft 的 RDP 端口 (3389) 端口转发到端口 (20202)。因此,我只需输入<my public IP address>:<port>
(例如134.111.23.443:20202
)即可通过 Mac 上的 Microsoft 远程桌面应用程序远程访问 Windows 10 计算机。
我想知道是否有一种方法可以使其更安全,例如通过 SSH 建立隧道,而不需要任何其他计算机(我只有家里的 Windows 10 机器通过固定电话连接到互联网,还有我的 MacBook,与我一起)。
这确实是一个很好的决定,因为 Microsoft 仍然不知道如何防止对 RDP 会话的暴力攻击。有帐户锁定策略(有一些缺点,请进一步阅读),在不错的@harrymc答案中描述得很好,因此那些至少拥有Windows Pro版本的人可以使用这样的工作流程。
如果您是家庭版的所有者,那么您可以通过直接编辑以下注册表项来激活帐户锁定策略:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\RemoteAccess\Parameters\AccountLockout
Run Code Online (Sandbox Code Playgroud)
MaxDenials
值并输入您希望锁定帐户之前的失败尝试次数。ResetTime
(分钟)值并将默认值(0xB40
十六进制表示 2,880 分钟(两天))更改为合理的值,例如 15-20 分钟。Windows 帐户锁定策略的问题是,如果其他人尝试暴力破解密码,您的计算机将被锁定。策略不依赖于发起者的 IP,仅计算登录尝试并触发帐户锁定事件,因此有效地禁用对所有者和攻击者的访问。
恕我直言,另一个更强大的保护是使用SSH公钥身份验证,它比基于密码的身份验证更强大。
您几乎通过提到 SSH 来回答您的问题。在 Windows PC 上设置cygwin,运行 SSH 服务并启用sshd_config
隧道并设置公钥身份验证,同时禁用纯密码身份验证(在家庭 LAN 上测试 ssh 连接是否成功)。
在您的路由器上转发一些非默认 SSH 端口 (22),例如 20202,就像您将 RDP 转发到此 Windows 计算机到 Windows PC 上的端口 22 一样(不要忘记禁用转发到 RDP)。当您要连接到 RDP 时,请使用以下脚本启动与远程 Windows PC 的第一个 SSH 会话:(适用
于基于 Unix 的操作系统的脚本,例如 Linux、BSD、MacOS,以及使用 cygwin 的用户。使用 Windows 作为客户端的用户请参阅下面的“连接”部分)
#!/bin/sh
# Script that can be use on remote client that running Unix based OS
RemotePC_IP=1.2.3.4 # Public IP address of your home
WindowsUserName=Gates # Windows user name on remote computer
RDPlocalListenPort=12345 # Local port that that will be forwarded to RDP
Path2prvKey='/path/to/private/key' # Path to private key
RemoteSSHport=20202 # The port that opened on your home router
# and forwarded to SSH service port on Windows PC
ssh -N -L ${RDPlocalListenPort}:localhost:3389 \
-i ${Path2prvKey} -p ${RemoteSSHport} ${WindowsUserName}@${RemotePC_IP}
# If you also want to use bunch of useful Unix utilites (that doesn't
# exist natively on Windows) besides of port forwarding, you can remove
# `-N` option from this script and use cygwin's terminal to run Windows's
# and Unix's console base programs remotely without starting RDP session.
Run Code Online (Sandbox Code Playgroud)
它将通过安全加密的 SSH 会话将本地端口 12345 转发到远程 Windows 计算机上的 RDP(3389) 端口,然后最终使用连接字符串连接到 RDPlocalhost:12345
这种保护 RDP 会话的方法的优点是使用非对称加密技术加密的通道比任何复杂的密码都要强大得多。除了强大的加密之外,还可以使用丰富的 Unix 实用程序通过安全通道管理远程 Windows PC。
使用 SSH 可以做一件更巧妙的事情 - 如果您家里没有静态 IP 地址,或者您不想完全信任 LogMeIn 或 TeamViewer 等公司,或者您的 PC 位于严格的防火墙后面,而您无法信任这些公司设置端口转发或者您无法控制主网关/防火墙,那么可以在反向模式下设置 SSH,其中 Windows PC 自动连接到具有您控制的静态 IP 的中间服务器。这样,您不需要直接连接到 Windows PC,而是连接到可以为许多计算机提供服务的中间服务器。当需要支持 IP 未知的移动客户时,以及当 IT 支持人员因公司机密性较高而需要支持公司的移动 PC 而无需使用第三方服务时,这种设置非常方便,可以降低数据泄露的风险。
虽然下面的安装过程看起来有点长,但实际上,当您了解其工作原理时,这种安装需要 10-15 分钟。
更新:从 Windows 10 v.1803 开始,Microsoft 附带了预安装的 OpenSSH 服务器和客户端,因此以下步骤适用于那些没有 Windows 10 或尚未升级到 Windows 10 v.1803 及更高版本的用户。
要在 Windows 上安装 SSH,请按照 Oracle 的文档进行操作,该文档详细介绍了如何设置 SSH 服务并配有屏幕截图。您只需按照此处的
5.3、5.4、5.5 节进行操作
我将发布安装 SSH 服务所需的最重要步骤。
setup-x86.exe
和setup-x86_64.exe
. 为您的机器选择适当的文件。如果您想使用除 SSH 之外的其他 Unix 基础实用程序,那么我的建议是x86
即使您的计算机是 64 位也使用版本,因为并非所有实用程序都移植到 64 位版本。Install for
将单选按钮设置为All usersc:\packages
)Direct connections
openssh
,,,,,,,openssl
unzip
xz
zip
mc
安装 Cygwin 后,导航到该C:\cygwin
目录,使用任何编辑器以编辑模式打开Cygwin.bat
文件,并在调用 bash shell 之前添加以下行。
set CYGWIN=binmode ntsec
如下例所示:
@echo off
C:
chdir C:\cygwin\bin
set CYGWIN=binmode ntsec
bash --login -i
要验证Cygwin ( cygrunsrv
) 是否正确安装,请运行
C:\cygwin\Cygwin.bat
,并执行以下命令:
cygrunsrv -h
如果 Cygwin 安装正确,则屏幕上会显示所有 Cygwin 帮助选项。但是,如果此命令返回错误消息,则您可能必须重新安装 Cygwin。
SSHD
服务,运行C:\cygwin\Cygwin.bat
,执行以下命令:ssh-host-config
*** Query: Should privilege separation be used? <yes/no>: yes
*** Query: New local account 'sshd'? <yes/no>: yes
*** Query: Do you want to install sshd as a service?
*** Query: <Say "no" if it is already installed as a service> <yes/no>: yes
*** Query: Enter the value of CYGWIN for the deamon: [] binmode ntsec
*** Query: Do you want to use a different name? (yes/no) yes/no
cyg_server
,请输入 no。然后系统会提示您以下问题:*** Query: Create new privileged user account 'cyg_server'? (yes/no) yes
*** Query: Please enter the password:
*** Query: Renter:
*** Query: Enter the new user name: cyg_server1
*** Query: Reenter: cyg_server1
*** Query: Create new privileged user account 'cyg_server1'? (yes/no) yes
*** Query: Please enter the password:
*** Query: Reenter:
Host configuration finished. Have fun!
c:\cygwin\etc\passwd
文件(如果存在)并运行以下命令:/bin/mkpasswd -l >/etc/passwd
passwd
通过运行 mcedit /etc/passwd
SYSTEM, LOCAL SERVICE, NETWORK SERVICE, NT SERVICE+TrustedInstaller, Guest
sshd_config
文件(SSH 服务):mcedit /etc/sshd_config
########################### Customization ##########################
Ciphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr
KexAlgorithms curve25519-sha256@libssh.org,diffie-hellman-group-exchange-sha256
MACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-ripemd160-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-512,hmac-sha2-256,hmac-ripemd160,umac-128@openssh.com
#
UseDNS no
UsePAM yes
LoginGraceTime 20
#
PermitRootLogin prohibit-password
PubkeyAuthentication yes
ChallengeResponseAuthentication no
PasswordAuthentication no
HostbasedAuthentication no
#
PermitTunnel yes
TCPKeepAlive no
ClientAliveInterval 30
ClientAliveCountMax 10
GatewayPorts no
AllowTcpForwarding yes
Run Code Online (Sandbox Code Playgroud)
现在需要生成用于公钥身份验证
的密钥
在cygwin
终端中运行以下命令:
mkdir -p ~/.ssh && chmod 700 ~/.ssh
cd ~/.ssh
echo > ~/.ssh/authorized_keys
cygwin
终端中运行以下命令:cd ~/.ssh
ssh-keygen -t ed25519 -o -a 127 -C "UserName" -f "UserName.ed25519.key"
cp -f UserName.ed25519.key.pub ~/.ssh/authorized_keys
PuTTY
并运行puttygen.exe
. 选择要生成为的密钥ED25519
并按Generate。将私钥保存到文件中,以后可以用作授权密钥。从标记为(用于传递到 OpenSSH 的公钥)的字段中选择顶部的公钥,右键单击选择并选择,copy
然后paste
将内容复制到~/.ssh/authorized_keys
最后通过运行以下命令启动 SSH 服务:
cygrunsrv -S sshd
Connection->SSH->Auth
并单击Browse按钮添加前面步骤中生成的私钥的路径。Connection->SSH->Tunnels
并输入字段Source port
12345
并放入localhost:3389
字段destination
,然后将单选按钮设置为Local
和Auto
并按Add按钮。Session
并在字段中输入Host Name
运行 SSH 的远程 Windows PC 的 IP 地址,并在字段中设置家庭路由器的远程侦听端口Port
。Saved Sessions
并保存配置。Remote Desktop Connection
程序并用于localhost:12345
通过 SSH 隧道通过 RDP 连接到远程计算机。 归档时间: |
|
查看次数: |
11176 次 |
最近记录: |