生成新的 SSH 密钥对。

以下命令将生成一个新的 4096 位 SSH 密钥对,并将您的电子邮件地址作为注释:

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

按 Enter 接受则默认文件位置和文件名:

要确认是否已经生成 SSH 密钥,您可以使用以下命令列出新的私钥和公钥:

ls ~/.ssh/id_*

/home/yourusername/.ssh/id_rsa /home/yourusername/.ssh/id_rsa.pub

复制公钥

登陆远程主机:

cat ~/.ssh/id_rsa.pub | ssh remote_username@server_ip_address "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"