内容纲要

1. 远程 windows 安装 msys2,开启 sshd 服务

pacman -S openssh
$ ssh-keygen -f /etc/ssh/ssh_host_rsa_key -N '' -t rsa
$ ssh-keygen -f /etc/ssh/ssh_host_dsa_key -N '' -t dsa
$ ssh-keygen -f /etc/ssh/ssh_host_ecdsa_key -N '' -t ecdsa
$ ssh-keygen -f /etc/ssh/ssh_host_ed25519_key -N '' -t ed25519

修改 /etc/ssh/sshd_config

PasswordAuthentication yes

启动 sshd

/usr/bin/sshd

2. vscode 安装 sftp 插件,用于打开远程文件夹

.vscode\sftp.json

{
  "name": "server_name",
  "host": "ip",
  "protocol": "sftp",
  "port": 22,
  "username": "Administrator",
  ##"password": "xxxxxx",
  "privateKeyPath": "C:/Users/USERNAME/.ssh/id_rsa",
  "remotePath": "/d/porjects",
  "uploadOnSave": true
}

配置免密登录,公私钥访问
在本机生成一对密钥

ssh-keygen -t rsa -b 4096 -C "test@gmail.com"

生成的公钥无法使用 ssh-copy-id 命令传递,需要手动拷贝到远程机,传递 id_rsa.pub 到远程机,或者拷贝粘贴字符串

在远程机

cat id_rsa.pub >> ~/.ssh/authorized_keys 
sudo chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys 

配置 vscode settings.json

{
    "terminal.integrated.shell.windows": "C:\\msys64\\usr\\bin\\bash.exe",
    "terminal.integrated.shellArgs.windows": [       
        "-c",
        "ssh -i ~/.ssh/id_rsa Administrator@IP"       
    ],
    "terminal.integrated.env.windows": {
        "PATH": "/mingw64/bin:/usr/local/bin:/usr/bin:/bin:/c/Windows/System32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0/"
    }
}

发表评论

电子邮件地址不会被公开。 必填项已用*标注