Linux 密钥登录
本文记录如何用 SSH 密钥登录远程服务器,避免每次都输入密码。
1. 在本地生成 SSH 密钥
Linux、macOS、Windows PowerShell 都可以运行:
bash
ssh-keygen -t ed25519 -C "Panchant@stu.xjtu.edu.cn"ssh-keygen -t ed25519 -C "Panchant@stu.xjtu.edu.cn"一路按回车即可。默认生成:
text
~/.ssh/id_ed25519 # 私钥,不能泄露
~/.ssh/id_ed25519.pub # 公钥,可以放到服务器~/.ssh/id_ed25519 # 私钥,不能泄露
~/.ssh/id_ed25519.pub # 公钥,可以放到服务器2. 把公钥复制到远程服务器
bash
ssh-copy-id 用户名@服务器IPssh-copy-id 用户名@服务器IP例如:
bash
ssh-copy-id ubuntu@192.168.1.100ssh-copy-id ubuntu@192.168.1.100这一步最后还需要输入一次服务器密码。
之后连接:
bash
ssh ubuntu@192.168.1.100ssh ubuntu@192.168.1.100就不再要求服务器密码了。
Comments