-
-
Save pitastrudl/2a25c66cbe0a1344f943 to your computer and use it in GitHub Desktop.
This file contains 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 | |
#this script installs and configures ssh server,generates a ssh key and adds the pub to the cfg | |
#should modify since generating pub/priv key on same machine is not a good idea | |
if [[ $EUID -ne 0 ]]; then #if script is ran as root | |
echo "This script must be run as root" 1>&2; | |
echo "Exiting..."; | |
exit 1; | |
fi | |
apt-get install openssh-server ssh; | |
cp -a /etc/ssh/sshd_config /etc/ssh/sshd_config_backup; #-a coz it saves attributes | |
sed -ie 's/Port 22/Port 25553/' /etc/ssh/sshd_config; | |
sed -ie 's/PermitRootLogin without-password/PermitRootLogin no/' /etc/ssh/sshd_config; | |
sed -ie 's/#PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config; | |
sed -ie 's/UsePAM yes/UsePAM no/' /etc/ssh/sshd_config; | |
echo "Enter name of private/public ssh key"; | |
read key; | |
ssh-keygen -t rsa -N "" -f $key; ##-N no passhprase, -f file | |
mkdir /home/$SUDO_USER/.ssh; | |
touch /home/$SUDO_USER/.ssh/authorized_keys; | |
cat $key.pub > /home/$SUDO_USER/.ssh/authorized_keys; | |
chown $SUDO_USER:$SUDO_USER $key; | |
chown $SUDO_USER:$SUDO_USER $key.pub; | |
chown -R $SUDO_USER:$SUDO_USER /home/$SUDO_USER/.ssh/; | |
chmod -R 700 /home/$SUDO_USER/.ssh; | |
chmod 600 /home/$SUDO_USER/.ssh/authorized_keys; | |
service ssh restart; | |
echo "done"; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment