linux 啓用指定用戶登錄,取消root ssh登錄

衆所周知,FreeBSD ssh默認登錄是不能直接用root來登錄,這樣一來,可以防範一些針對ssh嗅探***,二來,普通用戶操作可以避免一些“安全事故”。但是可惜的是,centos系列默認ssh都可以root直接登錄,這樣的帶來危害實在太大,本文下面所寫的shell,將大大簡化配置centos 普通用戶ssh登錄,避免因失誤造成,ssh登錄失敗。

#!/bin/bash
#desc: written by cuixh blog.zjyxh.com
useradd user
echo "user" > /etc/sshusers
sed -i '1aauth required pam_listfile.so item=user sense=allow file=/etc/sshusers onerr=fail' /etc/pam.d/sshd
sed -i "12aPort $RANDOM" /etc/ssh/sshd_config
sed -i "s/#PermitRootLogin yes/PermitRootLogin no/" /etc/ssh/sshd_config
sed -n "13p" /etc/ssh/sshd_config
/sbin/service sshd restart

將此腳本複製到chssh.sh,並在當前目錄下執行此腳本。比如,bash chessh.sh。或者下載現成的chssh.sh,比如 wget http://docs.zjyxh.com/linux/system/chssh.sh;bash chssh.sh;

最後設置user用戶密碼,passwd user


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章