Linux运维知识之Linux下配置SSH无密码登录
小标 2019-01-03 来源 : 阅读 968 评论 0

摘要:本文主要向大家介绍了Linux运维知识之Linux下配置SSH无密码登录,通过具体的内容向大家展现,希望对大家学习Linux运维知识有所帮助。

本文主要向大家介绍了Linux运维知识之Linux下配置SSH无密码登录,通过具体的内容向大家展现,希望对大家学习Linux运维知识有所帮助。


用ssh-keygen创建公钥



[root@qzweb1 .ssh]# 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:
e0:be:39:e4:08:a0:4c:e7:16:f5:bc:80:68:14:59:8a root@qzweb1
The key's randomart image is:
+--[ RSA 2048]----+
| .+.             |
|.o.  .           |
|E.. o +          |
|.+ + o +         |
|=.o . o S        |
|...o ...         |
|  .. +.          |
|    . oo         |
|      o.         |
+-----------------+



查看生成出来的密钥



[root@qzweb1 .ssh]# cd ~/.ssh/
[root@qzweb1 .ssh]# ls -l
总用量 12
-rw-------  1 root root 1675 11月 23 15:14 id_rsa
-rw-r--r--  1 root root  393 11月 23 15:14 id_rsa.pub
-rw-r--r--. 1 root root 3176 11月 22 10:45 known_hosts
[root@qzweb1 .ssh]#



下发公钥至目标机器



[root@qzweb1 .ssh]# scp id_rsa.pub 192.168.113.132:~/.ssh/
root@192.168.113.132's password: 
id_rsa.pub                                                                                                                                                                                                                                  100%  393     0.4KB/s   00:00    
[root@qzweb1 .ssh]#



配置目标机并设置文件和目录权限



[root@qzweb2 ~]# cd ~/.ssh/
[root@qzweb2 .ssh]# ls
id_rsa.pub
[root@qzweb2 .ssh]# cat id_rsa.pub >> authorized_keys
[root@qzweb2 .ssh]# chmod 600 authorized_keys  
[root@qzweb2 .ssh]# chmod 700 -R ~/.ssh 
[root@qzweb2 .ssh]#



使用SSH进行连接



[root@qzweb1 .ssh]# ssh 192.168.113.132
Last login: Thu Nov 23 13:42:21 2017 from 192.168.81.24


相关说明


创建的~/.ssh/id_rsa、id_rsa.pub的文件,其中第一个为密钥,第二个为公钥。过程中会要求输入密码,为了ssh访问过程无须密码,可以直接回车。


ssh-keygen:生成秘钥的部分参数:

-t指定算法

-f 指定生成秘钥路径

-N 指定密码


相关说明2


ssh-copy-id 命令可以把本地的ssh公钥文件安装到远程主机对应的账户下。用法:


ssh-copy-id -i /root/.ssh/id_rsa 192.168.1.11

0
The authenticity of host '192.168.1.11 (192.168.1.11)' can't be established.
RSA key fingerprint is 6e:34:d4:8c:fb:72:72:3a:49:7a:14:23:20:59:ea:28.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.11' (RSA) to the list of known hosts.
root@192.168.1.11's password: (输入192.168.1.11 root密码)
Now try logging into the machine, with "ssh '192.168.2.11'", and check in:

  .ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

ssh-copy-id -i /root/.ssh/id_rsa 192.168.1.12
同上

ssh-copy-id -i /root/.ssh/id_rsa 192.168.1.13
同上


本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注系统运维Linux频道!

本文由 @小标 发布于职坐标。未经许可,禁止转载。
喜欢 | 0 不喜欢 | 0
看完这篇文章有何感觉?已经有0人表态,0%的人喜欢 快给朋友分享吧~
评论(0)
后参与评论

您输入的评论内容中包含违禁敏感词

我知道了

助您圆梦职场 匹配合适岗位
验证码手机号,获得海同独家IT培训资料
选择就业方向:
人工智能物联网
大数据开发/分析
人工智能Python
Java全栈开发
WEB前端+H5

请输入正确的手机号码

请输入正确的验证码

获取验证码

您今天的短信下发次数太多了,明天再试试吧!

提交

我们会在第一时间安排职业规划师联系您!

您也可以联系我们的职业规划师咨询:

小职老师的微信号:z_zhizuobiao
小职老师的微信号:z_zhizuobiao

版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
 沪公网安备 31011502005948号    

©2015 www.zhizuobiao.com All Rights Reserved

208小时内训课程