怎样部署ssh免密钥登录
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了怎样部署ssh免密钥登录相关的知识,希望对你有一定的参考价值。
SSH免密钥登录其实很简单,只需几步就能部署完成。测试环境:CentOS Linux release 7.1.1503 (Core)
步骤如下:
1. 在主机上生成公钥和密钥!
[ Thegod:~ chengde$ ssh-keygen #一直回车即可!
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/chengde/.ssh/id_rsa):
/Users/chengde/.ssh/id_rsa already exists.
...
2. 第一步执行完成后,会在你当前登录的用户的宿主目录下生成一个.ssh的目录,在.ssh目录下会生成两个文件(id_rsa和id_rsa.pub)私钥和公钥
Thegod:~ chengde$ cd .ssh/
Thegod:.ssh chengde$ ls
id_rsa id_rsa.pub known_hosts
3. 将公钥(id_rsa.pub)移动到要免密码登录的服务器的用户家目录下的.ssh目录下并改名为authorized_keys
Thegod:.ssh chengde$ ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]
Remarks: 如果需要免密钥登录的服务器的用户家目录下的.ssh目录下已经有authorized_keys这个文件了,那么就将公钥追加到这个文件中,如果覆盖了里面的内容就更改了!(此内容只适合多台服务器免密钥登录这台服务器)
4.测试,完成
Thegod:.ssh chengde$ ssh [email protected]
Last failed login: Sun Jan 28 21:13:04 CST 2018 from 218.65.30.30 on ssh:notty
There were 883 failed login attempts since the last successful login.
Last login: Sun Jan 28 20:30:20 2018 from 139.215.216.12
[[email protected] ~]#
以上是关于怎样部署ssh免密钥登录的主要内容,如果未能解决你的问题,请参考以下文章
Debian9.5下ssh密钥登录配置步骤(免密码登录)和ssh-keygen 命令常用参数
Xshell配置ssh免密码登录-密钥公钥(Public key)