如何实现Centos6.5中ssh免密码登录配置

2023-04-14 16:28:00 密码 配置 如何实现

如何实现Centos6.5中ssh免密码登录配置

如果你想要实现ssh免密码登录,你需要做的第一件事就是在客户端生成一个密钥对。如果你还没有生成密钥对,可以使用如下命令来生成:

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

如果一切顺利的话,你会看到如下输出:

Generating public/private rsa key pair. Enter file in which to save the key (/home/you/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/you/.ssh/id_rsa. Your public key has been saved in /home/you/.ssh/id_rsa.pub. The key fingerprint is: 01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db your_email@example.com The key's randomart image is: +--[ RSA 2048]----+ | .oo. | | . .o | | o . . | | . o . | | S o | | . + | | . o | | oE. | | .o. | +-----------------+

接下来,你需要将生成的公钥复制到远程服务器上。你可以使用如下命令来将公钥复制到远程服务器上:

ssh-copy-id -i ~/.ssh/id_rsa.pub user@remote_host

如果一切顺利的话,你会看到如下输出:

/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/you/.ssh/id_rsa.pub" /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys user@remote_host's password:

上面的命令会将你的公钥添加到远程服务器的~/.ssh/authorized_keys文件中。

接下来,你可以尝试使用如下命令来从客户端登录到远程服务器:

ssh user@remote_host

如果一切顺利的话,你会看到如下输出:

Welcome to Ubuntu 14.04.1 LTS (GNU/Linux 3.13.0-32-generic x86_64) * Documentation: https://help.ubuntu.com/ System information as of Wed Sep 17 22:03:54 UTC 2014 System load: 0.0 Processes: 93 Usage of /: 15.5% of 39.34GB Users logged in: 0 Memory usage: 17% IP address for eth0: 10.0.2.15 Swap usage: 0% Graph this data and manage this system at: https://landscape.canonical.com/ Get cloud support with Ubuntu Advantage Cloud Guest: http://www.ubuntu.com/business/services/cloud 0 packages can be updated. 0 updates are security updates. New release '16.04.1 LTS' available. Run 'do-release-upgrade' to upgrade to it. Last login: Wed Sep 17 22:03:54 2014 from 10.0.2.2

如果你看到上面的输出,说明你已经成功的实现了ssh免密码登录。

相关文章