远程和本机的环境设置
远程主机安装ssh-server
# ubuntu
sudo apt install openssh-server
# centos
sudo yum install openssh-server && sudo systemctl start sshd.service && sudo systemctl enable sshd.service
本地安装ssh-client
windows 安装openssh
# ubuntu
sudo apt install openssh-client
# centos
sudo yum install openssh-clients
安装vscode和插件
本地安装vscode
打开vscode,安装remote-ssh插件。
vscode配置
普通密码登录
打开vscode,ctrl + shift + P输入Remote-SSH:Open Configuration File,打开~.ssh\config文件
写入如下配置:
Host 192.168.233.130
HostName 192.168.233.130
User root
Port 22
使用私钥免密登录
生成ssh key
macOS / Linux:
ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa-remote-ssh
Windows:
ssh-keygen -t rsa -b 4096 -f "$HOME\.ssh\id_rsa-remote-ssh"
Host 172.17.200.208
HostName 172.17.200.208
User root
IdentityFile C:/Users/Administrator/.ssh/id_rsa-remote-ssh
将客户端id_rsa-remote-ssh.pub
中的内容写入服务端~/.ssh/authorized_keys