Chinaunix首页 | 论坛 | 博客
  • 博客访问: 427181
  • 博文数量: 58
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 623
  • 用 户 组: 普通用户
  • 注册时间: 2013-04-26 18:48
个人简介

在生存面前,那纯洁的理想,原来是那么脆弱不堪!

文章分类

全部博文(58)

文章存档

2022年(1)

2021年(1)

2019年(3)

2018年(6)

2017年(6)

2016年(14)

2015年(10)

2014年(16)

2013年(1)

我的朋友

分类: 系统运维

2016-03-31 11:42:03

  互联网环境下,经常会遇到有人扫描登录22端口,尝试密码登录。我们可以使用下面几个方法,做安全方面的加固。
   1,强制所有用户秘钥登录。   
  2,只禁用root密码登录。
   3,对sshd服务做IP过滤。
一,强制使用秘钥登录服务器。
   1,首先修改/etc/ssh/sshd_config文件。
     修改 PasswordAuthentication no   表示禁止密码方式的认证。
     重新载入配置# /etc/init.d/sshd reload。

   2,生成秘钥对。
     rsa算法加密的秘钥,过程是首先生成私钥,然后按照私钥生成唯一的公钥,所以公钥可以公开,但私钥绝对不能公开。

在Linux服务器下。

  1. [root@Centos64 ~]# ssh-keygen
  2. Generating public/private rsa key pair.
  3. Enter file in which to save the key (/root/.ssh/id_rsa): ./id_rsa
  4. Enter passphrase (empty for no passphrase):   ## 这里也可以不加入密码,直接敲两次回车。
  5. Enter same passphrase again:
  6. Your identification has been saved in ./id_rsa.   ##私钥文件名
  7. Your public key has been saved in ./id_rsa.pub.   ##公钥文件名
  8. 。。。。。。。
     第3行,指定了存放在当前路径。
     第4行要求添加一个密码,这里可以为你的私钥添加密码,这样即使别人得到你的私钥,也要求输入密码使用,当然自己使用,也需要输入密码。

   3,配置秘钥登录。
     在你要登录的用户home目录下。新建文件夹.ssh(这是一个隐藏文件夹,如果存在就不新建)。例如root用户。

拷贝公钥文件到  .ssh文件夹下,并命名为authorized_keys

  1. cp id_rsa.pub /root/.ssh/authorized_keys
  2. chmod 644 /root/.ssh/authorized_keys      主要去掉其他用户的写权限。
 
4,在其他终端登录。

拷贝私钥 id_rsa 到终端。

  1. chmod 600 id_rsa     ##去掉终端上其他用户的读写权限。
  2. ssh -i id_rsa 192.168.158.129   ##登录。
 
5,如果你终端使用的windows系统,可以使用xshell工具。
   登录 
   也可以使用这个工具生成秘钥对,然后把公钥拷贝在服务器上。

二,禁止root使用密码登录服务器。
   1,编辑/etc/ssh/sshd_config文件。
     修改: PermitRootLogin without-password

   2,当然更绝的办法是把root禁止登录。但至少保证其他用户可以登录吧,不然会很悲剧。
     编辑/etc/ssh/sshd_config文件。
     修改: PermitRootLogin no  

三,对扫描22端口的IP进行封锁。

使用下面命令筛选IP。

  1. cat secure* | awk '/Failed password for root/{print $11;} /Failed password for invalid user/{print $13;}' | sort | uniq -c | sort -n
     结果应该已经出来了。
     直接将IP添加到/etc/hosts.deny

格式如下:

  1. sshd: 183.3.202.108
  2. sshd: 218.25.208.90
  3. sshd: 218.93.208.66
  4. sshd: 217.128.203.5
  5. sshd: 58.218.205.97
  6. sshd: 58.218.199.166
  7. sshd: 58.218.211.11
  8. sshd: 58.218.211.244
  9. sshd: 58.218.204.248
  10. sshd: 58.218.204.30
  11. sshd: 81.31.166.193
阅读(3597) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~