当前位置: 移动技术网 > 网络运营>安全>加解密 > linux-openssh高级密码策略

linux-openssh高级密码策略

2018年02月02日  | 移动技术网网络运营  | 我要评论
 昨日突然看见有人在网上询问怎么加固openssh 使用密码+证书双重认证,看到了一种解决方法,就是使用openvpn先登录上去 再使用openssh证书登录,我的妈呀,为了加个密码还要专门搞个openvpn,其实如果咱们的现有部署本身就要openvpn也没什么说的,可是如果不需要就多余了。而且又开了一个黑客大门! 

 

    好像openssh不支持密码和证书同时认证,要么证书,要么密码随便哪个成功就好了,不能"且“关系!  怎么办呢,考虑了一下有几个方案:

 

   1,最简单的方法就是制作key时加上密码短语,不过这个不方便集中管理!

 

 

 

   2,使用以下代码加固/etc/profile   

 

 

trap 'echo "Please Ener Your Password!!" ' 1 2 3 9 15 17 18 19 20 24

 

#这里是密码,你可以先md5sum sha512sum加密也是可以的!

mima=123

clear

stty -echo

echo -n "--:"

read key

echo " "

cishu=1

while [ "$key" != "$mima" ]

do

echo -n "--:"

read key

echo " "

cishu=`expr $cishu + 1`

while [ $cishu -gt 10 ]

do

stty echo

 

#这里执行退出返回linux登陆状态

exit 1

done

done

clear

echo "wellcom !! Now time is `date`!"

stty echo

echo " "

 

 

  把以上代码加到/etc/profile末尾,不管你是ssh登陆还是直接linux登陆,登陆后还要进行二次登陆在多用户环境下!单用户不考虑了!让黑客傻眼!!

 

 

 

3,使用tomoyo-mac加固系统,这个强大点可以实现二次密码认证,或者多个密码策略,根据输入的密码不同实现不同的权限!!实现代码:

 

   首先建立1个认证脚本 aut1

 

echo "password" | sha1sum#!/bin/sh -p

 

hash="c8fed00eb2e87f1cee8e90ebbe870c190ac3848c  -"

 

read -r -s -e -p "Password: " password

hash_attempt="$(echo "$password" | sha1sum)"

sleep 2

if [ "$hash_attempt" = "$hash" ]; then

  exec $SHELL

else

  echo "Authentication failed"

fi  然后设置tomoyo-mac 

 

         锁定/usr/sbin/sshd域到<kernel>下方便管理

 

initialize_domain /usr/sbin/sshd from any       在/usr/sbin/sshd 产生的 /bin/bash域下设置强制权限,只能执行auth1程序!

 

file execute /bin/auth1 exec.realpath="/bin/auth1"锁定由auth1产生的域/bin/bash的权限,方便集中管理keep_domain any from <kernel> /usr/sbin/sshd /bin/bash /bin/auth1 /bin/bash      之后就是/usr/sbin/sshd /bin/bash /bin/auth1 /bin/bash 域 进行强制权限控制了!很简单,不过很灵活,咱们可以使用不同的auth1 auth2 auth3认证 不同的权限集!

 

 

 好了以上就是对openssh认证加固了,当然了,最新出现的google二维码认证也是可以的,不过太麻烦了还要手机拍照。费劲!要是google死了,怎么登陆呢!话说到这里,还是顺便讲讲openssh安全加固吧:

 

   1,使用sshd_config 限制allowuser 密码登陆次数 等等安全控制

 

 

 

   2,没有必要不要使用dropbear 相关ssh-serer绝对没有openssh安全稳定,openbsd出品必属精品!

 

 

 

  3,下载最新稳定版openssh-6.2p1 gcc fstack-protect-all加固,可以顺便修改version.h伪装下,编译选项为最小安装就好了什么pam utmp tcptrap全部关闭呵呵!

 

 

 

  4,使用强大的grsecurity 加固内核,添加溢出保护patch  paxctl -PEMRXS sshd!

 

 

 

  5,当然是openssh证书+密码短语登陆了,加上附加的密码认证 三重认证了!没必要吧!!!

 

 

 

  6,iptables -I INPUT -m time 加上时间控制,并发控制等等!!

 

 

 

  7,狠点再加上grsecurty chroot 补丁 加固linux chroot 功能对sshd加固,分区只读锁定openssh所在的分区!(只读锁定是一个危险的功能,开启了只有重启才能更改!)

 

 

 

    好了基本上就这些了,以上这些就是从网络层 密码认证层 程序溢出层 虚拟沙盒层加固了openssh!希望大家能用的到!

 

 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网