#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: 2a:ad:45:20:74:8b:bf:8f:c4:a8:6e:af:46:50:6b:ea root@localhost.localdomain The key's randomart p_w_picpath is: +--[ RSA 2048]----+ | . . | | ..o . | | .o.o | |. oo . | |.o . . S | |.. o + . | |o . = + | | E . * | |=oo.o . | +-----------------+ #ssh-copy-id -i ~/.ssh/id_rsa.pub 12.0.0.16 root@12.0.0.16's password: Now try logging into the machine, with "ssh '12.0.0.16'", and check in: .ssh/authorized_keys to make sure we haven't added extra keys that you weren't expecting. [CCDT-QH-业务导航-1-root-<ccdt>]~#ssh 12.0.0.16 Last login: Sat Aug 5 10:27:32 2017 from 12.0.0.15 [CCDT-QH-业务导航-2-root-<~>]~#
#ssh-keygen -t rsa 三个回车生成密钥对 ###生成rsa密钥对,默认保存在~/.ssh/{id_rsa,id_rsa.pub} ###id_rsa私钥本身保存的 id_rsa.pub公钥被连主机保存的 #ssh-copy-id -i ~/.ssh/id_rsa.pub 12.0.0.16 ###将公钥copy到将要登陆主机(12.0.0.16)中,默认(此位置是ssh配置文件中定义的)位置为~/.ssh/authorized_keys文件中 无需密码登陆执行scp ssh 完成。。
服务器配置完整的步骤应该是:linux
(1)生成密钥公钥copy到服务器上,私钥保存在本地数据库
(2)配置hosts.allow hosts.deny指名ssh容许连接的白名单bash
(3)禁止使用密码登陆服务器
(4)(可选)禁止root用户远程登陆dom
----------------------------------------------------------------------------------------ssh
#编辑sshd_config文件
ide
vi /etc/ssh/sshd_config
spa
#禁用密码验证
rest
PasswordAuthenticationno
code
#启用密钥验证
RSAAuthentication yes
PubkeyAuthentication yes
#指定公钥数据库文件
AuthorsizedKeysFile.ssh/authorized_keys
重启SSH服务前建议多保留一个会话以防不测
go go go。。。