-
Notifications
You must be signed in to change notification settings - Fork 0
/
login_root.sh
51 lines (46 loc) · 1.17 KB
/
login_root.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env bash
#控制是否允许root通过ssh登录,
usage="Usage: login_root.sh [root_on|root_off|password_on|password_off]"
root_off(){
#关闭root通过ssh登录
sed -i "s/^#PermitRootLogin.*/PermitRootLogin no/g" /etc/ssh/sshd_config
sed -i "s/^PermitRootLogin.*/PermitRootLogin no/g" /etc/ssh/sshd_config
service sshd restart
echo "root登录已关闭"
}
root_on(){
#允许root通过ssh登录
sed -i "s/^PermitRootLogin.*/#PermitRootLogin no/g" /etc/ssh/sshd_config
echo "root登录已开启"
service sshd restart
}
password_off(){
#关闭密码认证
sed -i "s/^PasswordAuthentication.*/PasswordAuthentication no/g" /etc/ssh/sshd_config
service sshd restart
echo "密码认证已关闭"
}
password_on(){
#开启密码认证
sed -i "s/^PasswordAuthentication.*/PasswordAuthentication yes/g" /etc/ssh/sshd_config
service sshd restart
echo "密码认证已开启"
}
case $1 in
root_on)
root_on
;;
root_off)
root_off
;;
password_on)
password_on
;;
password_off)
password_off
;;
*)
echo $usage
exit 1
;;
esac