Centos7下实现免密码登录

一、生成密钥

[[email protected] ~]# ssh-keygen
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:
SHA256:pvR6iWfppGPSFZlAqP35/6DEtGTvaMY64otThWoBTuk [email protected]
The key‘s randomart image is:
+---[RSA 2048]----+
|  .  o.          |
|.o  . .          |
|+. o . . o       |
| Eo o . +        |
|   o o..S.       |
|  o ..oO.o       |
| . . ..=*oo      |
|  ..o *[email protected]+ .     |
|  [email protected]+.o..    |
+----[SHA256]-----+

生成之后会在用户的根目录生成一个 “.ssh”的文件夹,进入“.ssh”会生成以下几个文件

authorized_keys id_rsa id_rsa.pub known_hosts

authorized_keys:存放远程免密登录的公钥,主要通过这个文件记录多台机器的公钥

id_rsa : 生成的私钥文件

id_rsa.pub : 生成的公钥文件

know_hosts : 已知的主机公钥清单

如果希望ssh公钥生效需满足至少下面两个条件:

1) .ssh目录的权限必须是700

2) .ssh/authorized_keys文件权限必须是600

二、远程免密登录

1.原理:

- 客户端向服务器端发出连接请求

- 服务器端向客户端发出自己的公钥

- 客户端使用服务器端的公钥加密通讯密钥然后发给服务器端

- 如果通讯过程被截获,由于窃听者即使获知公钥和经过公钥加密的内容,但不拥有私 钥依然无法解密(RSA算法)

- 服务器端接收到密文后,用私钥解密,获知通讯密钥

2.常用以下几种方法:

2.1通过ssh-copy-id的方式

[[email protected] ~]# ssh-copy-id -i [email protected]
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.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
[email protected]‘s password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh ‘[email protected]‘"
and check to make sure that only the key(s) you wanted were added.

2.2通过scp将内容写到对方的文件中

[[email protected] .ssh]# scp -p ~/.ssh/id_rsa.pub [email protected]:/root/.ssh/authorized_keys
[email protected]‘s password:
id_rsa.pub 100% 408 0.4KB/s 00:00
[[email protected] .ssh]#
[[email protected] .ssh]#
[[email protected] .ssh]#
[[email protected] .ssh]# ssh [email protected]
Last login: Mon Oct 10 01:27:02 2016 from 192.168.80.10
[[email protected] ~]#

或者

scp ~/.ssh/id_rsa.pub [email protected]<remote_ip>:pub_key //将文件拷贝至远程服务器
$ cat ~/pub_key >>~/.ssh/authorized_keys //将内容追加到authorized_keys文件中, 不过要登录远程服务器来执行这条命令

原文地址:https://www.cnblogs.com/areyouready/p/9716271.html

时间: 2024-07-31 13:47:48

Centos7下实现免密码登录的相关文章

Redhat下SSH免密码登录步骤

Redhat下SSH免密码登录步骤: 被登录端: # mkdir /root/.ssh 另需禁用selinux(需重启服务器),否则会失败 # vi /etc/selinux/config SELINUX=disabled  (默认为:SELINUX=enforcing) :wq 登录端: # ssh-keygen 路径为默认 密码可为空 # mv ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys # scp ~/.ssh/authorized_keys [ema

Linux下SSH免密码登录

转自:http://haitao.iteye.com/blog/1744272 ssh配置 主机A:10.0.5.199 主机B:10.0.5.198 需要配置主机A无密码登录主机A,主机B 先确保所有主机的防火墙处于关闭状态. 在主机A上执行如下: 1. $cd ~/.ssh 2. $ssh-keygen -t rsa  --------------------然后一直按回车键,就会按照默认的选项将生成的密钥保存在.ssh/id_rsa文件中. 3. $cp id_rsa.pub author

Linux下实现免密码登录(超详细)

1.Linux下生成密钥 ssh-keygen的命令手册,通过"man ssh-keygen"命令: 通过命令"ssh-keygen -t rsa" 生成之后会在用户的根目录生成一个 ".ssh"的文件夹 进入".ssh"会生成以下几个文件 authorized_keys:存放远程免密登录的公钥,主要通过这个文件记录多台机器的公钥 id_rsa : 生成的私钥文件 id_rsa.pub : 生成的公钥文件 know_hosts

linux下A免密码登录B

linux下A免密码登录B 现在有两台linux服务器A:192.168.1.111,B:192.168.1.112 1.在A(192.168.123.111)生成公钥私钥对,命令如下: ssh-keygen  -t rsa -P '',如图: -P表示密码,-P '' 就表示空密码,也可以不用-P参数,这样就要三车回车,用-P就一次回车. 2.在/root/目录下生成了id_rsa.id_rsa.pub文件,如图: id_rsa是私钥,id_rsa.pub是公钥. 3.将公钥复制到B(192.

Ubuntu下ssh免密码登录安装

1.首先在本机安装openssh-server和openssh-client. 命令:sudo apt-get install openssh-server openssh-client 2.在检查当前的目录下有没有.ssh这个文件,没有的话就mkdir下. 3.生成公钥与私钥.命令:ssh-keygen -t rsa 4.将.ssh文件中的id_isa_pub复制到其他机器的authorized_keys下.并修改authorized_keys权限为600. 5.ssh nodeXX即可. U

Hadoop分布式模式下SSH免密码登录

1.Hadoop中为什么要配置免密码登录 最近在学习Hadoop,在集群中,Hadoop控制脚本依赖SSH来执行针对整个集群的操作.例如,某个脚本能够终止并重启集群中的所有守护进程.所以,需要安装SSH,但是,SSH远程登陆的时候,需要密码验证,集群中数千台计算机,数千台计算机都需要手工输入密码,这是不太现实的,所以,就需要配置SSH无密码登录. 2.环境 Hadoop中有三个节点,分别是centosNameNode,centosDateNode1,centosDateNode2,我们现在要实现

linux下ssh免密码登录设置

每次登录远程主机使用密码难免有点烦人,在此介绍一种方式,可使用ssh密钥进行免密码登录. ssh密钥生成 ssh-keygen:此命令用于生成密钥. 常用到的命令选项如下: -t:用于指定密钥类型,rsa或者dsa,一般使用rsa: -b:指定密钥长度: -e:读取openssh的私钥或者公钥文件: -C:添加注释: -f:指定用来保存密钥的文件名: -i:读取未加密的ssh-v2兼容的私钥/公钥文件,然后在标准输出设备上显示openssh兼容的私钥/公钥: -l:显示公钥文件的指纹数据: -N

Linux下SSH免密码登录(转)

搭建hadoop集群的时候一定会用到的就是SSH免密码登录 [[email protected] ~]$ ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/home/hadoop/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Yo

Linux ssh下实现免密码登录

1.Linux 生成密钥 ssh-keygen -t rsa 进入".ssh"会生成以下几个文件 id_rsa : 生成的私钥文件 id_rsa.pub : 生成的公钥文件 know_hosts : 已知的主机公钥清单 2.远程免密登录(现在我们就需要把key文件复制到其它几台服务器了,) 常用以下几种方法: a.通过ssh-copy-id的方式  命令: ssh-copy-id (服务器IP) 常见错误: [root@test ~]# ssh-copy-id -i ~/.ssh/id