码迷,mamicode.com
首页 > 其他好文 > 详细

ssh安全优化-更改SSH服务器端远程登录的配置

时间:2018-08-06 21:44:45      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:就是   服务器端   success   reload   bee   been   false   配置文件   date   

1、备份原始文件

[root@szxjdw01-a-pro-14 ~]# cp /etc/ssh/sshd_config /etc/ssh/sshd_config.ori
[root@szxjdw01-a-pro-14 ~]# vim /etc/ssh/sshd_config
#Port 2213行修改为Port 52113
PermitRootLogin yes 131行修改为PermitRootLogin no
#PermitEmptyPasswords no 60行修改为PermitEmptyPasswords no
GSSAPIAuthentication yes  75行修改为GSSAPIAuthentication no
UseDNS no 129行默认不需要修改


快捷方式:

直接把这5项目加入到配置文件/etc/ssh/sshd_config的第13行,方便,不需要一个一个配置找了。

切勿把这4项放到配置文件的最后面,此方法是错误的,因为配置文件中有重复的,默认是最前面的那个生效的,所以一定不能直接把这5项目加入/etc/ssh/sshd_config的最后一行。

#####by jeremy at 2018-08-06#####
Port 52113
PermitRootLogin no
PermitEmptyPasswords no
UseDNS no
GSSAPIAuthentication no
#####by jeremy at 2018-08-06#####

添加普通用户和密码

[root@szxjdw01-a-pro-14 ~]# useradd sysadm
[root@szxjdw01-a-pro-14 ~]# echo jayae86|passwd --stdin sysadm
Changing password for user oldboy.
passwd: all authentication tokens updated successfully.

重启生效:restart和reload都可以

[root@szxjdw01-a-pro-14 ~]# /etc/init.d/sshd restart
Stopping sshd:                                             [  OK  ]
Starting sshd:                                             [  OK  ]
[root@szxjdw01-a-pro-14 ~]# logout

注销,然后切换sysadm,端口52113登录即可。

[oldboy@szxjdw01-a-pro-14 ~]$ whoami
sysadm

更加增强安全:拒绝所有网段登录,只开放安全网段登录

su - 
#切换到root账号下面修改


#拒绝所有ssh连接,修改完成后立即生效,不需要重启,不需要重启ssh服务

[root@shz-b-web-11 ~]# vim /etc/hosts.deny  
#
# hosts.deny    This file contains access rules which are used to
#               deny connections to network services that either use
#               the tcp_wrappers library or that have been
#               started through a tcp_wrappers-enabled xinetd.
#
#               The rules in this file can also be set up in
#               /etc/hosts.allow with a 'deny' option instead.
#
#               See 'man 5 hosts_options' and 'man 5 hosts_access'
#               for information on rule syntax.
#               See 'man tcpd' for information on tcp_wrappers
#
sshd:ALL


#只允许如下网段和IP地址连接,修改完成后立即生效,不需要重启ssh服务

[root@shz-b-web-11 ~]# vim /etc/hosts.allow 
#
# hosts.allow   This file contains access rules which are used to
#               allow or deny connections to network services that
#               either use the tcp_wrappers library or that have been
#               started through a tcp_wrappers-enabled xinetd.
#
#               See 'man 5 hosts_options' and 'man 5 hosts_access'
#               for information on rule syntax.
#               See 'man tcpd' for information on tcp_wrappers
#
sshd:223.204.67.158/255.255.255.255    #公司内网IP
sshd:10.1.1.0/255.255.255.0    #服务器内网IP网段
sshd:10.1.2.0/255.255.255.0    #服务器内网IP网段


除了前面介绍的安全知识以外,还有更高级的SSH安全策略,具体如下。

1) 更改SSH监听的IP,使其仅监听内网IP。命令如下:

[root@szxjdw01-a-back-13 ~]# sed -n '13,20p' /etc/ssh/sshd_config
#####by jeremy#2018-08-06#####
Port 52113
ListenAddress 10.0.0.7:52113#企业仅指定监听本机内网IP地址
PermitRootLogin no
PermitEmptyPasswords no
UseDNS no
GSSAPIAuthentication no
#####by jeremy#2018-08-06#####

2)通过防火墙限制仅能使用内网IP连接此服务器。限制命令如下:

iptables -I INPUT -p tcp --dport 52113 -s 10.0.0.0/24 -j ACCEPT
#默认规则为DROP时的限制SSH命令

3)通过拨号到×××服务器,然后从局域网访问这些服务器,提升安全性。其实Linux主机安全就像我们居住的房子一样安全。

4)工作中的系统安全重点就是互联网TCP/IP连接、对外的Web服务器断开http 80和https 443的安全控制。


ssh安全优化-更改SSH服务器端远程登录的配置

标签:就是   服务器端   success   reload   bee   been   false   配置文件   date   

原文地址:http://blog.51cto.com/sandshell/2155432

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