Created
April 19, 2018 01:03
-
-
Save nicholasadamou/a9b34225aad7565107aaebf13398633c to your computer and use it in GitHub Desktop.
Reconfigure OpenSSH keys & to start on boot.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Uncomment a string within a given file | |
# $FILE is the targeted file | |
# $KEY is the string that is currently commented '#' (String must contain '#' or else 'sed' will return '1') | |
uncomment_str() { | |
FILE="$1" | |
KEY="$2" | |
sed -i "$FILE" -e "/$KEY/s/#//g" | |
} | |
# Reconfigure OpenSSH Server | |
$(cd /etc/ssh && dpkg-reconfigure openssh-server) | |
# Configure OpenSSH runlevels | |
update-rc.d -f ssh remove | |
update-rc.d -f ssh defaults | |
$FILE="/etc/ssh/sshd_config" | |
$KEY="#PermitRootLogin yes" | |
if [ cat "$FILE" | grep "$KEY" ]; then | |
# Configure '/etc/ssh/ssh_config' to allow 'root' login | |
uncomment_str "$FILE" "$KEY" | |
# retsart OpenSSH service | |
sudo service ssh restart | |
fi | |
# Enable SSH on boot | |
update-rc.d -f ssh enable 2 3 4 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment