-
Notifications
You must be signed in to change notification settings - Fork 38
/
ssh.sh
94 lines (88 loc) · 2.51 KB
/
ssh.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env bash
##一键开启ssh登陆
if [[ ! "$USER" == "root" ]]; then
echo -e "\033[41;33m 警告:请使用root用户操作!~~ \033[0m"
exit 1
fi
function system_check() {
if [[ "$(. /etc/os-release && echo "$ID")" == "centos" ]]; then
system_centos
elif [[ "$(. /etc/os-release && echo "$ID")" == "ubuntu" ]]; then
apt -y update
system_ubuntu
elif [[ "$(. /etc/os-release && echo "$ID")" == "debian" ]]; then
apt -y update
system_debian
elif [[ "$(. /etc/os-release && echo "$ID")" == "alpine" ]]; then
system_alpine
else
echo -e "\033[41;33m 不支持您的系统 \033[0m"
exit 1
fi
}
function system_centos() {
if [[ ! -f /etc/ssh/sshd_config ]]; then
echo -e "\033[33m 安装SSH \033[0m"
yum install -y openssh-server
systemctl enable sshd.service
ssh_PermitRootLogin
service sshd restart
else
ssh_PermitRootLogin
service sshd restart
fi
echo -e "\033[32m 开启root账户SSH完成 \033[0m"
exit 0
}
function system_ubuntu() {
if [[ ! -f /etc/ssh/sshd_config ]]; then
echo -e "\033[33m 安装SSH \033[0m"
apt-get install -y openssh-server
ssh_PermitRootLogin
service ssh restart
else
ssh_PermitRootLogin
service ssh restart
fi
echo -e "\033[32m 开启root账户SSH完成 \033[0m"
exit 0
}
function system_debian() {
if [[ ! -f /etc/ssh/sshd_config ]]; then
echo -e "\033[33m 安装SSH \033[0m"
apt install -y openssh-server
ssh_PermitRootLogin
service ssh restart
else
ssh_PermitRootLogin
service ssh restart
fi
echo -e "\033[32m 开启root账户SSH完成 \033[0m"
exit 0
}
function system_alpine() {
if [[ ! -f /etc/ssh/sshd_config ]]; then
echo -e "\033[33m 安装SSH \033[0m"
apk add openssh-server
apk add openssh-client
rc-update add sshd
ssh_PermitRootLogin
service sshd restart
else
ssh_PermitRootLogin
service sshd restart
fi
echo -e "\033[32m 开启root账户SSH完成 \033[0m"
exit 0
}
function ssh_PermitRootLogin() {
if [[ `grep -c "ClientAliveInterval 30" /etc/ssh/sshd_config` == '0' ]]; then
sed -i '/ClientAliveInterval/d' /etc/ssh/sshd_config
sed -i '/ClientAliveCountMax/d' /etc/ssh/sshd_config
sh -c 'echo ClientAliveInterval 30 >> /etc/ssh/sshd_config'
sh -c 'echo ClientAliveCountMax 6 >> /etc/ssh/sshd_config'
fi
sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config
sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config
}
system_check "$@"