Skip to content

Instantly share code, notes, and snippets.

@beenhere4hours
Last active August 29, 2015 14:18
Show Gist options
  • Save beenhere4hours/48736bc0ef709b508326 to your computer and use it in GitHub Desktop.
Save beenhere4hours/48736bc0ef709b508326 to your computer and use it in GitHub Desktop.
VPS Setup 1 - SSH and Access
# login - gain access to the box
ssh root@dmasi.us
# open 2 connections as we will need access if the changes below fail
# set up user
# set some vars
MYUSERNAME="dmasi"
MYUSERKEY="<pub key>"
useradd $MYUSERNAME
mkdir -p -m 755 /home/$MYUSERNAME/.ssh
chown $MYUSERNAME.$MYUSERNAME /home/$MYUSERNAME/.ssh/
touch /home/$MYUSERNAME/.ssh/authorized_keys
echo $MYUSERKEY >> /home/$MYUSERNAME/.ssh/authorized_keys
# Configure Sudo for this user (allows the user to access sudo without logging in)
cp -pf /etc/sudoers /etc/sudoers.$(date +%Y%m%d%H%M%S).orig
sed -i 's/#.*//g' /etc/sudoers
sed -i '/^ *$/d' /etc/sudoers
echo $MYUSERNAME 'ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers
cat /etc/sudoers
visudo -c
# Setup SSHD [OpenSSH SSH daemon]
cp -prf /etc/ssh/sshd_config /etc/ssh/sshd_config.$(date +%Y%m%d%H%M%S).orig
sed -i -e 's/#.*//' -e 's/[ ^I]*$//' -e '/^$/ d' /etc/ssh/sshd_config
sed -i '/PermitRootLogin/d' /etc/ssh/sshd_config
sed -i '/PubkeyAuthentication/d' /etc/ssh/sshd_config
sed -i '/PasswordAuthentication/d' /etc/ssh/sshd_config
echo 'PermitRootLogin no' >> /etc/ssh/sshd_config
echo 'PubkeyAuthentication yes' >> /etc/ssh/sshd_config
echo 'PasswordAuthentication no' >> /etc/ssh/sshd_config
echo 'UseDNS no' >> /etc/ssh/sshd_config
cat /etc/ssh/sshd_config
service sshd restart
# exit and log back in as your user
exit
ssh dmasi@dmasi.us
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment