VScode远程ssh登录
生成自己的ssh密钥
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
-t rsa 表示生成 RSA 类型的密钥,-b 4096 表示密钥长度为 4096 位,-C 后是你的邮箱作为标识。
Linux保存路径:~/.ssh/id_rsa
Windows保存路径:C:\Users\YourUsername.ssh\id_rsa
生成自己的ssh密钥
将公钥上传到远程服务器
1、windows下需要安装git bash
2、copy密钥到你的服务器上
ssh-copy-id username@server_address
配置 SSH 免密登录
Linux:~/.ssh/config
Widows:C:\Users\YourUsername.ssh\config
Host server_name
HostName server_address
User username
IdentityFile C:\Users\YourUsername\.ssh\config
测试Vscode远程免密登录
在 VSCode 中,按下 Ctrl + Shift + P,输入 Remote-SSH: Connect to Host,选择刚刚配置的 myserver(或相应的服务器别名)。
出现 channel 3: open failed: administratively prohibited: open failed解决方案
修改sshd_config文件里面的内容
vim /etc/ssh/sshd_config
把下面两个字段修改为yes
AllowTcpForwarding yes
PermitTunnel yes
重启sshd服务
sudo systemctl restart sshd
如果还是不行
# 打开sshd_config
vim /etc/ssh/sshd_config
# 修改配置文件
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
# 重启sshd
sudo systemctl restart sshd