更新时间:2023-12-05 14:00:04
在要从中登录 的客户端计算机上,运行ssh-keygen
.要快速,轻松地进行操作,只需在所有问题上按回车即可.这将在〜/.ssh中创建一个密钥对.具体来说,〜/.ssh/id_rsa是您的私钥(保持这一安全),而〜/.ssh/id_rsa.pub是您的公钥(可以分发).
On the client machine you wish to login from, run ssh-keygen
. For a quick and easy key, just hit enter on all of the questions. This will create a key pair in ~/.ssh. Specifically, ~/.ssh/id_rsa is your private key (keep this one safe), and ~/.ssh/id_rsa.pub is your public key (okay to distribute).
将您的公钥(〜/.ssh/id_rsa.pub)复制到您要登录到的服务器上(例如scp ~/.ssh/id_rsa.pub me@myserver:
.在服务器上,运行cat id_rsa.pub >> .ssh/authorized_keys
.确保它具有正确的权限,您可以运行chmod 644 ~/.ssh/authorized_keys
.此外,您现在还可以删除复制过来的id_rsa.pub文件.
Copy your public key (~/.ssh/id_rsa.pub) onto the server that you wish to login to (e.g. scp ~/.ssh/id_rsa.pub me@myserver:
. On the server, run cat id_rsa.pub >> .ssh/authorized_keys
. To make sure that it has the correct permissions, you can run chmod 644 ~/.ssh/authorized_keys
. Also, you can now delete the id_rsa.pub file that you copied over.
就是这样!您应该具有从客户端到服务器的无密码登录.如果要从服务器到客户端的无密码登录,则必须重复客户端和服务器的交换过程.
That's it! You should have password-less login from client to server. You must repeat the process with client and server swapped if you want password-less login from server to client.
注释:
ssh-keygen
时提示之一),但是每次登录时都必须输入该密码.解决方案解决这个问题的方法是使用ssh-agent.ssh-keygen
), but then you will have to enter that password every time you log in. The solution to this problem is to use ssh-agent.