Remote - SSH 配置记录

本文最后更新于:2020年7月20日 晚上

注意:这篇博文配置的本地环境为Windows10,远端环境为Ubuntu,参考资料在文章末尾。

1. Remote - SSH

You can:

  • Develop on the same operating system you deploy to or use larger, faster, or more specialized hardware than your local machine.
  • Quickly swap between different, remote development environments and safely make updates without worrying about impacting your local machine.
  • Access an existing development environment from multiple machines or locations.
  • Debug an application running somewhere else such as a customer site or in the cloud.

2. 配置过程

2.1 SSH keys

1. 生成本地的 SSH key pair

  • 首先检查Windows上是否已有一个SSH key,一般为C:\Users\your-user\.ssh\id_rsa.pub。如果是macOS / Linux,则在~/.ssh/id_rsa.pub

  • 如果没有则通过终端,使用以下命令生成一个SSH key pair

1
ssh-keygen -t rsa -b 4096

2. 授权远端

在本地终端中运行以下命令将SSH key pair上传至远端,注意命令的内容要根据实际进行调整

1
2
3
4
export USER_AT_HOST="your-user-name-on-host@hostname"
export PUBKEYPATH="$HOME/.ssh/id_rsa.pub"

ssh-copy-id -i "$PUBKEYPATH" "$USER_AT_HOST"

3. 远端安装ssh-server服务

1
sudo apt-get install openssh-server

2.2 问题解决

  1. 错误提示:Bad owner or permissions on C:\\Users\\USER/.ssh/config
  • 解决方案:setting a content in the vs codes

参考资料