在本文中,我们将允许您使用SSH密钥为Linux系统配置无密码登录,以连接到远程Linux服务器,而无需输入密码,这还将增加两台Linux服务器之间的信任,以便于文件传输。
SSH是一种开放源代码和受信任的网络协议,用于登录到远程服务器以执行命令和程序。这也用于使用安全副本(SCP)通过网络将文件从一台计算机传输到另一台计算机。
# ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: 71:de:c6:b4:c4:8b:31:70:5f:bd:96:60:56:8e:74:b9 root@centos The key's randomart image is: +--[ RSA 2048]----+ | . . .o+. | | o o.=+.. | | . + B...+| | + O o E | | S o * . | | . | | | | | | | +-----------------+
为了安全起见,密钥本身使用强密码保护,如果使用密码保护密钥,则SSH代理可用于缓存密码。
ssh-copy-id root@192.168.1.84 root@192.168.1.84's password: Now try logging into the machine, with "ssh 'root@192.168.1.84'", and check in: .ssh/authorized_keys to make sure we haven't added extra keys that you weren't expecting.
ssh root@192.168.1.84 Last login: Thu Apr 14 17:30:19 2016 from 192.168.2.225 #
言归正传,我们无需任何密码即可登录到远程服务器
通过配置上述3个步骤,我们将能够在不输入密码的情况下登录到远程服务器,这是最安全的问题,有人可能会看到密码并入侵服务器,这些身份验证类型将帮助我们编写自动备份以运行并在远程服务器上计划。