-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig_ssh.sh
More file actions
56 lines (50 loc) · 1.65 KB
/
Copy pathconfig_ssh.sh
File metadata and controls
56 lines (50 loc) · 1.65 KB
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
#!/bin/bash
# 检查文件是否存在
function sshd_config()
{
# 移除注释并修改 Port
# sed -i 's/#Port 22/Port 22/' /etc/ssh/sshd_config
# if [ -z "$(grep 'Port 22' /etc/ssh/sshd_config)" ]; then
# echo "修改ssh端口失败"
# else
# echo "修改ssh端口成功"
# fi
#grep '^Port 22$' /etc/ssh/sshd_config
# 修改 PermitRootLogin
sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
if [ -z "$(grep 'PermitRootLogin yes' /etc/ssh/sshd_config)" ]; then
echo "修改PermitRootLogin失败"
else
echo "修改PermitRootLogin成功"
systemctl restart ssh
echo 已重启ssh服务
fi
#grep '^PermitRootLogin $' /etc/ssh/sshd_config
# 修改 ClientAliveInterval
sed -i 's/#ClientAliveInterval.*/ClientAliveInterval 60/' /etc/ssh/sshd_config
if [ -z "$(grep 'ClientAliveInterval 60' /etc/ssh/sshd_config)" ]; then
echo "修改ClientAliveInterval失败"
else
echo "修改ClientAliveInterval成功"
fi
# 修改 ClientAliveCountMax
sed -i 's/#ClientAliveCountMax.*/ClientAliveCountMax 10/' /etc/ssh/sshd_config
if [ -z "$(grep 'ClientAliveCountMax 10' /etc/ssh/sshd_config)" ]; then
echo "修改ClientAliveCountMax失败"
else
echo "修改ClientAliveCountMax成功"
fi
}
if [ -f "/etc/ssh/sshd_config" ]; then
sshd_config
else
echo "/etc/ssh/sshd_config 文件不存在"
echo 是否安装openssh-server
read -p "y/n: " is_install
if [ "$is_install" = "y" ]; then
sudo apt-get install openssh-server
else
exit 1
fi
sshd_config
fi