centos安装怎么免密登陆

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos安装怎么免密登陆相关的知识,希望对你有一定的参考价值。

参考技术A 1ssh免密钥认证,2或者把密码写到全局变量(不推荐)

Centos7实现ssh免密登陆

1通过ssh-copy-id的方式

 1 [[email protected] ~]# ssh-copy-id -i [email protected]
 2 /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
 3 /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
 4 /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
 5 [email protected]s password:
 6 
 7 Number of key(s) added: 1
 8 
 9 Now try logging into the machine, with:   "ssh ‘[email protected]"
10 and check to make sure that only the key(s) you wanted were added.

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

1 [[email protected] .ssh]# scp -p ~/.ssh/id_rsa.pub [email protected]192.168.91.135:/root/.ssh/authorized_keys
2 [email protected]192.168.91.135s password: 
3 id_rsa.pub 100% 408 0.4KB/s 00:00 
4 [[email protected] .ssh]# 
5 [[email protected] .ssh]# 
6 [[email protected] .ssh]# 
7 [[email protected] .ssh]# ssh [email protected]192.168.91.135
8 Last login: Mon Oct 10 01:27:02 2016 from 192.168.91.133
9 [[email protected] ~]#

或者

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

3通过Ansible实现批量免密 

[Avoid close]
192.168.91.132
192.168.91.133
192.168.91.134
//执行命令进行免密操作
ansible <groupname> -m authorized_key -a "user=root key=‘{{ lookup(‘file‘,‘/root/.ssh/id_rsa.pub‘) }}‘" -k

示例:
[[email protected] sshpass-1.05]# ansible test -m authorized_key -a "user=root key=‘{{ lookup(‘file‘,‘/root/.ssh/id_rsa.pub‘) }}‘" -k
  SSH password: ----->输入密码
  192.168.91.135 | success >> {
  "changed": true, 
  "key": "ssh-rsa    AAAAB3NzaC1yc2EAAAABIwAAAQEArZI4kxlYuw7j1nt5ueIpTPWfGBJoZ8Mb02OJHR8yGW7A3izwT3/uhkK7RkaGavBbAlprp5bxp3i0TyNxa/apBQG5NiqhYO8YCuiGYGsQAGwZCBlNLF3gq1/18B6FV5moE/8yTbFA4dBQahdtVP PejLlSAbb5ZoGK8AtLlcRq49IENoXB99tnFVn3gMM0aX24ido1ZF9RfRWzfYF7bVsLsrIiMPmVNe5KaGL9kZ0svzoZ708yjWQQCEYWp0m+sODbtGPC34HMGAHjFlsC/SJffLuT/ug/hhCJUYeExHIkJF8OyvfC6DeF7ArI6zdKER7D8M0SM  WQmpKUltj2nltuv3w== [email protected]", 
  "key_options": null, 
  "keyfile": "/root/.ssh/authorized_keys", 
  "manage_dir": true, 
  "path": null, 
  "state": "present", 
  "unique": false, 
  "user": "root"
  }

 

以上是关于centos安装怎么免密登陆的主要内容,如果未能解决你的问题,请参考以下文章

centos/redhat 7 配置ssh免密登陆

Ubuntu 配置 ssh 登陆

CentOS SSH免密登陆

安装centos7 搭配linux集群 并进行 ssh免密登录(图文超详细)

安装centos7 搭配linux集群 并进行 ssh免密登录(图文超详细)

Spark集群框架搭建VM15+CentOS7+Hadoop+Scala+Spark+Zookeeper+HBase+Hive