Skip to content

Instantly share code, notes, and snippets.

@sergeyfarin
Last active August 26, 2018 13:34
Show Gist options
  • Save sergeyfarin/5561543aa6dbd946f6fec61170885046 to your computer and use it in GitHub Desktop.
Save sergeyfarin/5561543aa6dbd946f6fec61170885046 to your computer and use it in GitHub Desktop.
VPS Ubuntu 18.04 setup via SSH
echo -e "This script will do \e[1minitial setup of VPS with Ubuntu 18.04\e[22m (from OVH, but will also work with many others)"
echo ""
echo -e "\e[1mDefining required parameters\e[22m"
echo -ne "Please enter \e[1mIP address\e[22m of new VPS: " && read vps_ip
echo -ne "Please enter \e[1musername\e[22m to create main user in your new VPS:" && read username
echo -e "'\e[38;2;255;127;0mNot asking for passwords, you will be prompted as required\e[39m"
echo ""
echo -e "Connecting to new VPS as \e[1mroot\e[22m first time"
echo -e "You will need to enter password that you should have received by e-mail from OVH"
ssh root@$vps_ip username='$username' /bin/bash <<'EOT'
echo -e "Connected as \e[3m$( whoami )\e[23m to \e[3m$( uname -a )\e[23m"
echo -e "Creating new user and setting privileges, you will be asked to enter password"
adduser --gecos "" $username
usermod -aG sudo $username
EOT
echo "Setting up access with SSH-RSA key, rather than password"
echo "Expecting that you already have created ssh_rsa public and private keys and they are stored in appropriate folder ~/.ssh/"
echo "First, copying your public key to VPS, you will be aked to enter user password"
ssh-copy-id $username@$vps_ip
echo ""
echo ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment