window配置vscode免密登录

722 阅读1分钟

EA050E47-B0C8-4e2f-8290-44AC5FE63198.png

window配置vscode免密登录

打开window的cmd命令行窗口

#中间过程需要多次点击回车按钮确认

ssh-keygen

将秘钥发送到目标机器上,

输入bash命令, 即可进入到linux操作命令模式

执行如下代码

PS C:\Users\admin\.ssh> ssh-copy-id -i id_rsa.pub root@服务器IP

root@服务器IP's password:

遇到问题

在windows10上配置时,会遇到如下错误:

ssh-copy-id : 无法将“ssh-copy-id”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。
# 解决方案是在powershell中,先执行以下内容:
function ssh-copy-id([string]$userAtMachine, $args){   
    $publicKey = "$ENV:USERPROFILE" + "/.ssh/id_rsa.pub"
    if (!(Test-Path "$publicKey")){
        Write-Error "ERROR: failed to open ID file '$publicKey': No such file"            
    }
    else {
        & cat "$publicKey" | ssh $args $userAtMachine "umask 077; test -d .ssh || mkdir .ssh ; cat >> .ssh/authorized_keys || exit 1"      
    }
}