vscode通过ssh连接远程服务器+免密登录(图文) |
您所在的位置:网站首页 › 服务器如何设置远程连接账号和密码 › vscode通过ssh连接远程服务器+免密登录(图文) |
一、连接ssh服务器
1.打开Visual Studio Code,进入拓展市场(Ctrl+Shift+X),下载拓展Remote - SSH 2. 点击远程资源管理器选项卡,并选择远程(隧道/SSH)类别 3. 点击ssh配置 4.在弹出的选择配置文件中,点击第一个 5.在config文件中输入以下内容 Host HostName Port 22 User如: 6.保存后点击左边刷新按钮 7.这时展开SSH,就能看到刚刚创建的配置了 8. 使用Ctrl + Shift + P,打开命令窗口,输入ssh connect to host,选择第一个(在当前窗口连接)或第二个(在新窗口连接)都可以 9.选择刚刚创建好的那个配置 10.询问是否保存known_hosts,选择Continue即可 11.输入访问的密码(即第5步配置的用户,其对应的登陆密码) 12.该用户第一次访问该服务器可以看到该提示信息,耐心等待即可,这时是插件在服务器上面安装需要的依赖,大约会占用服务器150mb左右的空间 13.如果长时间都一直是该情况,可以使用Ctrl + Shift + P,打开命令窗口,输入reload window来重新加载窗口(会要求你重新手动输入密码) 14.最终显示如下页面就代表已经连接成功了 1.生成ssh使用的公钥/密钥对,请从客户端上的 PowerShell 或 cmd 提示符运行以下命令,具体使用方法详细见:微软官方 ssh-keygen -t rsa2.选择的配置文件就是之前连接到服务器使用的配置文件,或者打开刚刚创建的公钥文件 3.进入到编辑页面后,选择id_rsa.pub 4.拷贝id_ras.pub文件中的内容 5.进入终端输入以下命令 echo "xxxx" >> ~/.ssh/authorized_keys如: 6.验证方式 使用Ctrl + Shift + P,打开命令窗口,输入重启窗口命令reload window,确认左下角进入到连接成功的状态,期间没有提示输入密码的窗口,即代表成功了这是因为服务器默认禁用了ssh密码登录权限。修改方法如下: 在服务器上的终端输入:sudo vim /etc/ssh/sshd_config,打开该文件。找到PasswordAuthentication,将其后的 no 改为 yes。重启ssh服务:sudo service sshd restart 2.对于堡垒机的解决方法(未验证)有时,您可能需要通过公司的内部网或防火墙从台式机或笔记本电脑连接到远程计算机。在这种情况下,您可能正在使用中间服务器或跳转框。如果您在配置为仅接受来自固定主机集的SSH连接的安全系统中工作,则这种设置非常有用。 要使用带有Remote - SSH扩展的跳转框设置,您可以使用ProxyCommand config选项。此配置将打开到跳转框的后台SSH连接,然后通过私有IP地址连接到目标。 您可以在SSH配置文件中设置ProxyCommand config选项,如下所示: # Jump box with public IP address Host jump-box HostName 52.179.157.97 User sana IdentityFile ~/.ssh/jumpbox # Target machine with private IP address Host target-box HostName User sana IdentityFile ~/.ssh/target ProxyCommand ssh -q -W %h:%p jump-box或者是 This requires making an ssh tunnel inside the bastion tunnel which will allow multiple connections: Add the following to your $HOME.ssh\config Host tunnel HostName 127.0.0.1 Port 2222 User mylogin StrictHostKeyChecking=No UserKnownHostsFile=\\.\NULAdd the tunnel connection to your Establish the tunnel connection: az network bastion tunnel --name mybastion --resource-group myrg --target-resource-id /subscriptions//resourceGroups/myrg/providers/Microsoft.Compute/virtualMachines/myvm --resource-port 22 --port 22Create an ssh tunnel in the bastion tunnel ssh -L 2222:127.0.0.1:22 [email protected]Have VSCode connect to your "tunnel" connection above. 参考以下文:Remote SSH via Azure Bastion (with AAD auth) · Issue #7179 · microsoft/vscode-remote-release (github.com)Visual Studio Code Remote SSH Tips and Tricks Make the limitations of the `az network bastion tunnel` feature explicit · Issue #98747 · MicrosoftDocs/azure-docs (github.com) |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |