added install ssh script

This commit is contained in:
Mathieu Broillet 2023-06-13 15:25:03 +02:00
parent c7d0275915
commit 42dc7ba207
No known key found for this signature in database
GPG Key ID: 7D4F25BC50A0AA32
2 changed files with 64 additions and 0 deletions

View File

@ -0,0 +1,62 @@
#!/bin/bash
if which ssh >/dev/null 2>&1; then
echo "SSH is installed"
exit 1
else
echo "SSH is not installed"
fi
if lsb_release -a 2>/dev/null | grep -q -E "Debian|Ubuntu"; then
echo "Running Debian or Ubuntu"
apt-get install openssh-server
systemctl start sshd
elif cat /etc/os-release 2>/dev/null | grep -q -i "alpine"; then
echo "Running Alpine"
# Stop and remove Dropbear
rc-service dropbear stop
rc-update del dropbear
apk del dropbear* -f
# Stop and remove SSHD
rc-service sshd stop
rc-update del sshd
apk del openssh* -f
# Clean up Dropbear and SSH configurations
rm -rf /etc/dropbear
rm -rf /etc/ssh
rm /etc/init.d/ssh
# Reboot now if needed
# reboot now
# Install OpenSSH and necessary packages
apk add openssh gcompat libstdc++ curl bash git grep
apk add procps --no-cache
# Start and add SSHD to startup
rc-service sshd start
rc-update add sshd
# Update AllowTcpForwarding setting
sed -i 's/^#*AllowTcpForwarding.*/AllowTcpForwarding yes/' /etc/ssh/sshd_config
# Update PermitTunnel setting
sed -i 's/^#*PermitTunnel.*/PermitTunnel yes/' /etc/ssh/sshd_config
# Uncomment the line if needed (remove '#' at the beginning)
sed -i 's/^#PermitTunnel.*/PermitTunnel yes/' /etc/ssh/sshd_config
# Restart the SSH service to apply the changes
/etc/init.d/sshd restart
else
echo "Unknown distribution"
exit 1
fi
# Set PermitRootLogin to prohibit-password
sed -i 's/^#*PermitRootLogin.*/PermitRootLogin prohibit-password/' /etc/ssh/sshd_config

View File

@ -1,3 +1,5 @@
#!/bin/bash
if which docker >/dev/null 2>&1; then if which docker >/dev/null 2>&1; then
echo "Docker is installed" echo "Docker is installed"
exit 1 exit 1