在本文中,我们将在 Linux 和 Ubuntu 服务器之间配置无密码身份验证。
配置环境
我们要在没有密码的情况下可以登录的机器。
| 主机名: | backupserver.test.local |
| IP 地址: | 192.168.229.128/24 |
| 操作系统: | Ubuntu 14.04 LTS |
| 用户名: | backupadm |
我们要登录到备份服务器的机器。
| 主机名: | dbserver.test.local |
| IP 地址: | 192.168.229.133/24 |
| 操作系统 : | CentOS 6.5 |
| 用户名: | oracle |
https://onitroad.com 更多教程
配置无密码身份验证:
登录到dbserver 。
生成一个没有任何密码短语的 RSA 公钥。
[oracle@dbserver ~]$ ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/home/oracle/.ssh/id_rsa): Created directory '/home/oracle/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/oracle/.ssh/id_rsa. Your public key has been saved in /home/oracle/.ssh/id_rsa.pub. The key fingerprint is: ca:2a:87:fc:7b:98:ae:d7:95:b3:35:b3:36:89:db:b4 oracle@dbserver.test.local The key's randomart image is: +--[ RSA 2048]----+ | | | | | | | | | S. | | . .+ + | | . . +o. =.= | | + =.o oo=. | | .B=o .oE. | +-----------------+ [oracle@dbserver ~]$
以上命令在 ~/.ssh 目录中生成两个文件。
将生成的 RSA 公钥 id_rsa.pub 文件传输到备份服务器。
[oracle@dbserver ~]$ scp .ssh/id_rsa.pub backupadm@backupserver:/home/backupadm/.ssh/rsa_dbserver_oracle The authenticity of host 'backupserver (backupserver)' can't be established. RSA key fingerprint is a2:38:20:d9:f6:93:04:fe:e5:09:cc:5d:b5:9a:7c:4c. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'backupserver' (RSA) to the list of known hosts. backupadm@backupserver's password: id_rsa.pub 100% 409 0.4KB/s 00:00 [oracle@dbserver ~]$
现在,连接到备份服务器并将 rsa_dbserver_oracle 合并到 ~/.ssh/authorized_keys。
backupadm@backupserver:~$ cd .ssh backupadm@backupserver:~/.ssh$ cat rsa_dbserver_oracle >> authorized_keys
连接到 dbserver 并尝试与备份服务器连接。
[oracle@dbserver ~]$ ssh backupadm@backupserver
Welcome to Ubuntu 14.04 LTS (GNU/Linux 3.13.0-24-generic x86_64)
* Documentation: https://help.ubuntu.com/
System information as of Sat Apr 2 21:10:02 PKT 2016
System load: 0.02 Processes: 246
Usage of /: 3.6% of 36.54GB Users logged in: 1
Memory usage: 16% IP address for eth0:192.168.229.128
Swap usage: 0%
Graph this data and manage this system at:
https://landscape.canonical.com/
Last login: Sat Apr 2 20:26:45 2016 from dbserver
backupadm@backupserver:~$
我们已经在Linux 服务器之间配置无密码 SSH 登录。
日期:2020-09-17 00:13:22 来源:oir作者:oir
