centos服务器ssh安全加强

今天偶然发现服务器是root直接连接的,还是默认22端口,感觉太不安全了,做了一下优化,操作如下!

1:修改ssh默认端口(/etc/ssh/sshd_config)

2:增加不同人员用户,通过su root切换root,这是为禁用root登录做准备.

#新增用户组
groupadd  test
#新增用户   
useradd test
#设置test用户密码
passwd	test
#给test用户增加test组权限
usermod -a -G test test

3:禁止root直接连接(/etc/ssh/sshd_config).将PermitRootLogin yes改为PermitRootLogin no.


4:增加各用户ssh操作日志(/etc/profile底部添加).


history
USER=`whoami`
USER_IP=`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'`
if [ "$USER_IP" = "" ]; then
USER_IP=`hostname`
fi
if [ ! -d /tmp/history ]; then
mkdir /tmp/history
chmod 777 /tmp/history
fi
if [ ! -d /tmp/history/${LOGNAME} ]; then
mkdir /tmp/history/${LOGNAME}
chmod 300 /tmp/history/${LOGNAME}
fi
export HISTSIZE=4096
DT=`date +"%Y%m%d_%H:%M:%S"`
export HISTFILE="/tmp/history/${LOGNAME}/${USER}@${USER_IP}_$DT"
chmod 600 /tmp/history/${LOGNAME}/*history* 2>/dev/null

5:以后新增用户方法如下:

useradd test1
passwd  test1
usermod -a -G test test1

大致情况就这样,后续有时间再继续优化,比如:限制IP登录,跳板机登录等。

此条目发表在 好文推荐, 网站架构 分类目录,贴了 , , 标签。将固定链接加入收藏夹。

评论功能已关闭。