Repository navigation
Expand file tree
/
Copy pathbash_insert_content.text
More file actions
81 lines (79 loc) · 4.11 KB
/
Copy pathbash_insert_content.text
File metadata and controls
81 lines (79 loc) · 4.11 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
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
- trigger: post-files
action: |-
#!/bin/sh
set -eux
systemctl disable iptables || true
systemctl enable sshd || true
systemctl enable ssh || true
# sshd_config
sed -i "s/^#\?\(Port\).*/\1 22/" /etc/ssh/sshd_config || true
sed -i -E 's/^#?(Port).*/\1 22/' /etc/ssh/sshd_config || true
sed -i 's/^#\?Port.*/Port 22/g' /etc/ssh/sshd_config || true
sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config || true
sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config || true
sed -i 's/#ListenAddress 0.0.0.0/ListenAddress 0.0.0.0/' /etc/ssh/sshd_config || true
sed -i 's/#ListenAddress ::/ListenAddress ::/' /etc/ssh/sshd_config || true
sed -i 's/#AddressFamily any/AddressFamily any/' /etc/ssh/sshd_config || true
sed -i 's/^#\?PubkeyAuthentication.*/PubkeyAuthentication yes/g' /etc/ssh/sshd_config || true
sed -i '/^#UsePAM\\|UsePAM/c #UsePAM no' /etc/ssh/sshd_config || true
sed -i '/^AuthorizedKeysFile/s/^/#/' /etc/ssh/sshd_config || true
# cloud-init
sed -i "s/^#\?\(Port\).*/\1 22/" /etc/ssh/sshd_config.d/50-cloud-init.conf || true
sed -i -E 's/^#?(Port).*/\1 22/' /etc/ssh/sshd_config.d/50-cloud-init.conf || true
sed -i 's/^#\?Port.*/Port 22/g' /etc/ssh/sshd_config.d/50-cloud-init.conf || true
sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config.d/50-cloud-init.conf || true
sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config.d/50-cloud-init.conf || true
sed -i 's/#ListenAddress 0.0.0.0/ListenAddress 0.0.0.0/' /etc/ssh/sshd_config.d/50-cloud-init.conf || true
sed -i 's/#ListenAddress ::/ListenAddress ::/' /etc/ssh/sshd_config.d/50-cloud-init.conf || true
sed -i 's/#AddressFamily any/AddressFamily any/' /etc/ssh/sshd_config.d/50-cloud-init.conf || true
sed -i 's/^#\?PubkeyAuthentication.*/PubkeyAuthentication yes/g' /etc/ssh/sshd_config.d/50-cloud-init.conf || true
sed -i '/^#UsePAM\\|UsePAM/c #UsePAM no' /etc/ssh/sshd_config.d/50-cloud-init.conf || true
sed -i '/^AuthorizedKeysFile/s/^/#/' /etc/ssh/sshd_config.d/50-cloud-init.conf || true
# other config
sed -i.bak '/^SELINUX=/cSELINUX=disabled' /etc/sysconfig/selinux || true
sed -i.bak '/^SELINUX=/cSELINUX=disabled' /etc/selinux/config || true
grep -q '^PermitRootLogin yes' /etc/ssh/sshd_config || echo "PermitRootLogin yes" >> /etc/ssh/sshd_config || true
mkdir -p /etc/modprobe.d/ || true
echo "install algif_aead /bin/false" > /etc/modprobe.d/disable-algif.conf || true
echo "Related repo https://github.com/oneclickvirt/lxd_images\n--by https://t.me/spiritlhl" >> /etc/motd || true
echo "Related repo https://github.com/oneclickvirt/lxd_images\n--by https://t.me/spiritlhl" >> /etc/banner || true
# ensure package manager database integrity
if command -v dpkg >/dev/null 2>&1; then
dpkg --configure -a || true
fi
if command -v rpm >/dev/null 2>&1; then
rpm --rebuilddb || true
fi
# clean package manager caches to reduce image size
if command -v apt-get >/dev/null 2>&1; then
apt-get clean || true
rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/*.deb || true
fi
if command -v dnf >/dev/null 2>&1; then
dnf clean all || true
rm -rf /var/cache/dnf/* || true
elif command -v yum >/dev/null 2>&1; then
yum clean all || true
rm -rf /var/cache/yum/* || true
fi
if command -v zypper >/dev/null 2>&1; then
zypper clean -a || true
rm -rf /var/cache/zypp/* || true
fi
if command -v pacman >/dev/null 2>&1; then
pacman -Sc --noconfirm || true
fi
if command -v emerge >/dev/null 2>&1; then
emerge --depclean || true
rm -rf /var/db/repos/gentoo/* /var/cache/distfiles/* /var/cache/binpkgs/* || true
fi
# clean temporary files and logs
rm -rf /tmp/* /var/tmp/* || true
find /var/log -type f \( -name "*.log" -o -name "*.gz" -o -name "*.1" \) -delete 2>/dev/null || true
truncate -s 0 /var/log/lastlog 2>/dev/null || true
types:
- vm
- container
variants:
- cloud
- default