码迷,mamicode.com
首页 > 系统相关 > 详细

linux配置无秘钥登陆

时间:2017-02-27 12:46:28      阅读:342      评论:0      收藏:0      [点我收藏+]

标签:2.3   bsp   写博客   ast   zed   版权   保护   否则   command   

                                linux配置无秘钥登陆

                                                    作者:尹正杰

版权声明:原创作品,谢绝转载!否则将追究法律责任。

 

       最近有点心烦,很少写博客了,后期的3个月里,估计更新的频率也不会太高,请见谅,今天给大家共享一下linux不用秘钥就可以访问服务器的一种方法,这样工作起来比较方便,如果感兴趣的小伙伴们可以看一下,具体配置内容如下:

 

       首先,我要明确一下我的系统环境,都是2台centos6.6的操作系统,内核都是2.6的.

 

 
第一台机器:
 
#1>.创建秘钥对
[root@yinzhengjie .ssh]# ifconfig em1 | grep "inet addr" | awk ‘{print $2}‘ | awk -F ":" ‘{print $2}‘
192.168.2.45
[root@yinzhengjie .ssh]#
[root@yinzhengjie .ssh]# ssh-keygen -t dsa
[root@yinzhengjie .ssh]# ll
总用量 8
-rw-------. 1 root root 668 2月 27 11:14 id_dsa
-rw-r--r--. 1 root root 606 2月 27 11:14 id_dsa.pub
[root@yinzhengjie .ssh]#
passphrase(密钥保护) 保留为空,否则使用ssh时将要求输入passphrase(密钥保护)
2>.共享秘钥对
[root@yinzhengjie .ssh]# scp id_dsa.pub 172.30.1.60:/root/.ssh/zabbix.key.pub
 
3>.授权
[root@yinzhengjie .ssh]# cat id_dsa.pub > authorized_keys
[root@yinzhengjie .ssh]# cat yinzhengjie.key.pub >> authorized_keys
 
4.测试登陆(在执行此操作之前。要确定另外的一台服务器已经完成了以上的三个操作)
[root@yinzhengjie ~]# ssh 172.30.1.60
reverse mapping checking getaddrinfo for bogon [172.30.1.60] failed - POSSIBLE BREAK-IN ATTEMPT!
Last login: Mon Feb 27 03:43:22 2017 from 192.168.2.45
-bash: “#Add: command not found
-bash: “#Add: command not found
[root@yinzhengjie ~]# ifconfig eth0 | grep "inet addr"| awk -F ":" ‘{print $2}‘ | awk ‘{print $1}‘
172.30.1.60
[root@yinzhengjie ~]#
5.查看日志情况
[root@yinzhengjie ~]# more /var/log/secure
Feb 27 11:39:01 bogon sshd[18831]: Received disconnect from 172.30.1.60: 11: disconnected by user
Feb 27 11:39:01 bogon sshd[18831]: pam_unix(sshd:session): session closed for user root
Feb 27 11:39:02 bogon sshd[18897]: reverse mapping checking getaddrinfo for bogon [172.30.1.60] failed - POSSIBLE BREAK-IN ATTEMPT!
Feb 27 11:39:02 bogon sshd[18897]: Accepted publickey for root from 172.30.1.60 port 37244 ssh2
Feb 27 11:39:02 bogon sshd[18897]: pam_unix(sshd:session): session opened for user root by (uid=0)
Feb 27 11:39:35 bogon sshd[18897]: Received disconnect from 172.30.1.60: 11: disconnected by user
Feb 27 11:39:35 bogon sshd[18897]: pam_unix(sshd:session): session closed for user root
[root@yinzhengjie ~]#
 
 
第二台机器:
#1>.创建秘钥对
[root@yinzhengjie .ssh]# ifconfig eth0 | grep "inet addr"| awk -F ":" ‘{print $2}‘ | awk ‘{print $1}‘
172.30.1.60
[root@yinzhengjie .ssh]# ssh-keygen -t dsa
2>.共享秘钥对
[root@yinzhengjie .ssh]# scp id_dsa.pub 192.168.2.45:/root/.ssh/yinzhengjie.key.pub
3>.授权
[root@yinzhengjie .ssh]# cat id_dsa.pub > authorized_keys
[root@yinzhengjie .ssh]# cat yinzhengjie.key.pub >> authorized_keys
4.测试登陆(在执行此操作之前。要确定另外的一台服务器已经完成了以上的三个操作)
[root@yinzhengjie .ssh]# ssh 192.168.2.45
reverse mapping checking getaddrinfo for bogon [192.168.2.45] failed - POSSIBLE BREAK-IN ATTEMPT!
Last login: Mon Feb 27 11:33:39 2017 from 192.168.2.45
[root@yinzhengjie ~]# exit
logout
Connection to 192.168.2.45 closed.
[root@yinzhengjie .ssh]# ifconfig eth0 | grep "inet addr"| awk -F ":" ‘{print $2}‘ | awk ‘{print $1}‘
172.30.1.60
[root@yinzhengjie .ssh]#
 

linux配置无秘钥登陆

标签:2.3   bsp   写博客   ast   zed   版权   保护   否则   command   

原文地址:http://www.cnblogs.com/yinzhengjie/p/6473094.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!