Featured image of post SSH 配置

SSH 配置

生成 SSH Key

1
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

自动保存在 ~/.ssh 文件夹内,文件 id_rsa 为私钥,文件 id_rsa.pub 为公钥

使用 SSH 免密登录

手工配置

将本地公钥粘贴至远程文件 ~/.ssh/authorized_keys 中,文件不存在则自行创建

命令配置

命令配置方式将会在认证之后,自动将本地公钥传输到远程 ~/.ssh/authorized_keys 文件夹里

替换以下命令中的 usernameremoteIP ,也可以替换 ~/.ssh/id_rsa.pub 来指定本地公钥文件

Linux

1
ssh-copy-id username@remoteIP -i ~/.ssh/id_rsa.pub

Windows

PowerShell 方式

1
type $env:USERPROFILE\.ssh\id_rsa.pub | ssh username@remoteIP "cat >> .ssh/authorized_keys"

CMD 方式

1
cat ~/.ssh/id_rsa.pub | ssh -p 22 username@remoteIP "cat >> ~/.ssh/authorized_keys"