-
Notifications
You must be signed in to change notification settings - Fork 1
/
ssh_sh.sh
97 lines (96 loc) · 4.29 KB
/
ssh_sh.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
95
96
97
#!/bin/sh
# by https://github.com/oneclickvirt/pve_lxc_images
# 2024.02.08
if [ "$(id -u)" -ne 0 ]; then
echo "This script must be executed with root privileges."
exit 1
fi
if [ "$(cat /etc/os-release | grep -E '^ID=' | cut -d '=' -f 2 | tr -d '"')" == "alpine" ]; then
apk update
apk add --no-cache openssh-server
apk add --no-cache sshpass
apk add --no-cache openssh-keygen
apk add --no-cache bash
apk add --no-cache curl
apk add --no-cache wget
apk add --no-cache lsof
cd /etc/ssh
ssh-keygen -A
chattr -i /etc/ssh/sshd_config
sed -i '/^#PermitRootLogin\|PermitRootLogin/c PermitRootLogin yes' /etc/ssh/sshd_config
sed -i "s/^#\?PasswordAuthentication.*/PasswordAuthentication yes/g" /etc/ssh/sshd_config
sed -i '/^#ListenAddress\|ListenAddress/c ListenAddress 0.0.0.0' /etc/ssh/sshd_config
sed -i '/^#AddressFamily\|AddressFamily/c AddressFamily any' /etc/ssh/sshd_config
sed -i "s/^#\?\(Port\).*/\1 22/" /etc/ssh/sshd_config
sed -i -E 's/^#?(Port).*/\1 22/' /etc/ssh/sshd_config
sed -i '/^#UsePAM\|UsePAM/c #UsePAM no' /etc/ssh/sshd_config
sed -E -i 's/preserve_hostname:[[:space:]]*false/preserve_hostname: true/g' /etc/cloud/cloud.cfg
sed -E -i 's/disable_root:[[:space:]]*true/disable_root: false/g' /etc/cloud/cloud.cfg
sed -E -i 's/ssh_pwauth:[[:space:]]*false/ssh_pwauth: true/g' /etc/cloud/cloud.cfg
/usr/sbin/sshd
rc-update add sshd default
chattr +i /etc/ssh/sshd_config
elif [ "$(cat /etc/os-release | grep -E '^ID=' | cut -d '=' -f 2 | tr -d '"')" == "openwrt" ]; then
opkg update
opkg install openssh-server
opkg install bash
opkg install openssh-keygen
opkg install shadow-chpasswd
opkg install chattr
opkg install cronie
opkg install cron
/etc/init.d/sshd enable
/etc/init.d/sshd start
cd /etc/ssh
ssh-keygen -A
chattr -i /etc/ssh/sshd_config
sed -i "s/^#\?Port.*/Port 22/g" /etc/ssh/sshd_config
sed -i "s/^#\?PermitRootLogin.*/PermitRootLogin yes/g" /etc/ssh/sshd_config
sed -i "s/^#\?PasswordAuthentication.*/PasswordAuthentication yes/g" /etc/ssh/sshd_config
sed -i 's/#ListenAddress 0.0.0.0/ListenAddress 0.0.0.0/' /etc/ssh/sshd_config
sed -i 's/#ListenAddress ::/ListenAddress ::/' /etc/ssh/sshd_config
sed -i 's/#AddressFamily any/AddressFamily any/' /etc/ssh/sshd_config
sed -i "s/^#\?PubkeyAuthentication.*/PubkeyAuthentication no/g" /etc/ssh/sshd_config
sed -i '/^AuthorizedKeysFile/s/^/#/' /etc/ssh/sshd_config
chattr +i /etc/ssh/sshd_config
/etc/init.d/sshd restart
# elif [ "$(grep . /etc/issue 2>/dev/null | cut -d \\ -f1 | sed '/^[ ]*$/d')" =~ *"Arch"* ]; then
# curl -slk https://raw.githubusercontent.com/SuperManito/LinuxMirrors/main/ChangeMirrors.sh -o ChangeMirrors.sh
# chmod 777 ChangeMirrors.sh
# ./ChangeMirrors.sh --use-official-source --web-protocol http --intranet false --close-firewall true --backup true --updata-software false --clean-cache false --ignore-backup-tips
# rm -rf /etc/pacman.d/gnupg/
# pacman-key --init
# pacman-key --populate archlinux
# pacman -Syyuu
# pacman -Sy --needed openssh
# pacman -Sy --needed bash
# pacman -Sy --needed chattr
# pacman -Sy --needed cronie
# pacman -Sy --needed cron
# systemctl enable sshd
# systemctl start sshd
# chattr -i /etc/ssh/sshd_config
# sed -i "s/^#\?Port.*/Port 22/g" /etc/ssh/sshd_config
# sed -i "s/^#\?PermitRootLogin.*/PermitRootLogin yes/g" /etc/ssh/sshd_config
# sed -i "s/^#\?PasswordAuthentication.*/PasswordAuthentication yes/g" /etc/ssh/sshd_config
# sed -i 's/#ListenAddress 0.0.0.0/ListenAddress 0.0.0.0/' /etc/ssh/sshd_config
# sed -i 's/#ListenAddress ::/ListenAddress ::/' /etc/ssh/sshd_config
# sed -i 's/#AddressFamily any/AddressFamily any/' /etc/ssh/sshd_config
# sed -i "s/^#\?PubkeyAuthentication.*/PubkeyAuthentication no/g" /etc/ssh/sshd_config
# sed -i '/^AuthorizedKeysFile/s/^/#/' /etc/ssh/sshd_config
# chattr +i /etc/ssh/sshd_config
# systemctl restart sshd
fi
/etc/init.d/cron enable || true
/etc/init.d/cron start || true
if [ -f "/etc/motd" ]; then
echo '' >/etc/motd
echo 'Related repo https://github.com/oneclickvirt/pve_lxc_images' >>/etc/motd
echo '--by https://t.me/spiritlhl' >>/etc/motd
fi
if [ -f "/etc/banner" ]; then
echo '' >/etc/banner
echo 'Related repo https://github.com/oneclickvirt/pve_lxc_images' >>/etc/banner
echo '--by https://t.me/spiritlhl' >>/etc/banner
fi
rm -f "$0"