SSH:不用密码登录

用SSH登录远程主机,每次都输入密码挺麻烦的,其实可以用密钥文件来登录:
1. 用ssh-keygen命令生成private/public密钥对,提示问题都用默认回答即可。

$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/guoyong/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/guoyong/.ssh/id_rsa.
Your public key has been saved in /home/guoyong/.ssh/id_rsa.pub.

2. 用ssh-copy-id命令把公钥复制到远程主机上,user就是你登录用的用户名

$ ssh-cody-id user@remotehost

3. 验证一下吧

$ ssh user@remotehost echo "it works"

One Reply to “SSH:不用密码登录”

Comments are closed.