设为首页 收藏本站
查看: 255|回复: 0

[经验分享] Linux ssh 安全配置

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2014-11-3 08:46:53 | 显示全部楼层 |阅读模式
                      Linux  ssh 安全登陆  
创建ssh密钥
[iyunv@localhost ~]# 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:
40:96:bf:a5:89:c2:66:a3:bd:dc:79:a3:b5:a8:1f:8d root@localhost.localdomain
The key's randomart image is:
+--[ RSA 2048]----+
|      o.         |
|     o.          |
|      ..         |
|       .. .      |
|   .   .S=       |
|    * .o+        |
|   = oE o        |
|  .... =o.       |
|    ++*o..       |
+-----------------+
[iyunv@localhost .ssh]# ls
id_rsa  id_rsa.pub         #把公钥上传到远程的linux机器上   
[iyunv@localhost .ssh]#     
[iyunv@localhost ~]# clear
[iyunv@localhost ~]# ssh-copy-id -i .ssh/id_rsa.pub root@10.0.0.2
The authenticity of host '10.0.0.2 (10.0.0.2)' can't be established.
RSA key fingerprint is fb:82:7c:05:f1:74:86:47:52:64:87:3c:86:fd:cd:ee.
Are you sure you want to continue connecting (yes/no)? yes    #第一次需要确认一下
Warning: Permanently added '10.0.0.2' (RSA) to the list of known hosts.
root@10.0.0.2's password:
Now try logging into the machine, with "ssh 'root@10.0.0.2'", and check in:

  .ssh/authorized_keys

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

[iyunv@localhost ~]#
[iyunv@localhost ~]# ssh 10.0.0.2      
Enter passphrase for key '/root/.ssh/id_rsa':      #需要输入密钥
Last login: Wed Oct 29 16:47:08 2014 from 10.0.0.1
[iyunv@postgresql ~]# ls -a .ssh/
.  ..  authorized_keys      # 公钥查看ok
[iyunv@postgresql ~]#         # 重启一下ssh就ok了。
为了使系统更加安全,关闭密码认证启用密钥认证
[iyunv@localhost ~]# vi /etc/ssh/sshd_config
Protocol 2                    #启用ssh2  
PubkeyAuthentication yes        #启用密钥认证
AuthorizedKeysFile      .ssh/authorized_keys   #密钥存放位置
PasswordAuthentication no                 #关闭密码认证
[iyunv@localhost ~]# /etc/init.d/sshd restart     #重启ssh 服务  
1.png

2.png        
把系统默认的22端口改为四位数端口,并且修改ssh文件
vi /etc/ssh/sshd_config
如果需要登陆,将公钥的文件拷贝出来就ok了。
如果需要使用工具的话,那么可以在工具上配置密钥
3.png        
前面创建的是单向的密钥
创建双向密钥对两个机器都执行 # ssh-keygen t rsa   使用相同的密钥
将生成的密钥拷贝对方机器~/.ssh/ 目录下  并且更改名字为  authorized_krys(两个名字修改后拷贝对方的用户~/.ssh/ 目录下) 修改sshd_config 文件
4.png vbx       
6.png    ,。        
测试
5.png        
不需要任何认证,还有锁定网络ip等
                   

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-26859-1-1.html 上篇帖子: redhat/centos的kickstart文件中指定磁盘安装和安装完毕弹出光盘并重启 下篇帖子: AIX6.1同步远程NTP服务器时钟配置
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表