ssh自动登录vscode配置

1.自动登录vscode 配置

方法一(推荐)
1. winows 下用ssh-keygen 生成公钥和秘钥(使用git Bash Here)

使用命令 
$ssh-keygen.exe -t rsa
(可以一路Enter)

2.将公钥发送到服务器

$ssh-copy-id -i ~/.ssh/id_rsa.pub username@192.168.2.22

此时会要求输一次服务器密码

/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/Users/username/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
username@192.168.2.22's password: 

Number of key(s) added:        1

Now try logging into the machine, with:   "ssh 'username@192.168.2.22'"
and check to make sure that only the key(s) you wanted were added.


3.vscode插件Remote Development如果已经配置好对应的服务器,那么下次再ssh登陆时,就不用输密码了

另外,一般vscode ssh的配置文件ssh_config路径C:\Users\xx-pc\.ssh,生成公钥私钥放的位置也在这儿

方法二(没试过)
1.将公钥文件id_rsa.pub传到远程服务器的authorized_keys文件中
$scp ~/.ssh/id_rsa.pub username@192.168.2.22:/home/ubuntu/.ssh/

2.添加公钥到authorized_keys

$cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

3.
$sudo vim /etc/ssh/sshd_config
在远程服务器(ubuntu)打开ssh配置文件/etc/ssh/sshd_config,,确认该文件是否有以下选项

- RSAAuthentication yes 

- PubkeyAuthentication yes

要确保有的情况下,才能用ssh key免密码登陆

4.切到VScode,执行远程ssh,即可免密登入。

 

2.生成一个新的SSH密钥方法

1.(windows在git bash中执行,如果没有git bash,需要安装)/(ubuntu 在终端中执行)

$ssh-keygen -t rsa -C “可以是邮箱,也可以任意”

一路回车即可

 

 

 

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Visual Studio Code (VSCode) 是一个强大的代码编辑器,支持多种语言和平台,并且可以通过扩展功能来增强其功能,包括使用 SSH 远程连接到服务器进行开发。配置 VSCodeSSH 让你可以直接在本地编辑并在远程服务器上运行代码。以下是基本的步骤: 1. **安装**: - 打开 VSCode,确保已经安装了 `Remote Development` 插件。如果没有,可以在扩展市场搜索并安装 "Remote - SSH"。 2. **设置SSH密钥**: - 如果你还没有 SSH 公钥对,可以在终端或命令提示符中生成一对(通常使用 `ssh-keygen` 命令)。 - 将公钥(默认为 `.ssh/id_rsa.pub`)的内容添加到远程服务器的 `.ssh/authorized_keys` 文件中,或者使用 `ssh-copy-id` 命令自动添加。 3. **配置SSH配置文件**: - 在你的本地电脑上,打开 VSCode,按 `Ctrl+Shift+P` 或者点击左下角的活动栏搜索,输入 "Remote-SSH: Edit Configuration File",选择相应的配置文件(通常是 `~/.ssh/config` 或者 `c:\Users\yourname\.ssh\config`)。 4. **添加配置项**: - 在配置文件中,添加一个新的 SSH 会话,例如: ``` Host your-remote-server HostName your.remote.server.address User your-username Port 22 IdentityFile ~/.ssh/id_rsa # 你的私钥路径 # 如果有密码,可以设置PasswordAuthentication yes # 如果有代理,可以设置ProxyCommand ``` 5. **连接到服务器**: - 保存配置后,你可以通过 Remote-Explorer 视图(`Ctrl+Shift+K, Ctrl+O`)或终端(`Terminal` > `New Terminal`,然后输入 `code your-remote-server`)来连接到远程服务器。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值