Skip to content

Instantly share code, notes, and snippets.

@amberj
Last active June 22, 2021 21:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save amberj/7e141f6140a2f4932b93 to your computer and use it in GitHub Desktop.
Save amberj/7e141f6140a2f4932b93 to your computer and use it in GitHub Desktop.
Initial setup of hosted VPS (which comes with 'root' access by default)
#!/bin/bash
# ABOUT:
#
# Use this set of commands to:
# - Change password of root account
# - Create a new user account, set it's password and grant sudo privileges
# on Ubuntu Linux.
# Change password of currently logged in 'root' account:
passwd
# Enter new password twice!
# Create new user 'user'
# -d means set the user's home directory to '/home/user'
# -m enforces useradd to create the home directory
sudo useradd -d /home/user -m user -s /bin/bash
# Set password for 'user'
sudo passwd user
# Enter password twice!
# Grant 'sudo' privileges to 'user'
sudo usermod -a -G sudo user
# Fix locale settings
echo "export LC_ALL=en_US.UTF-8" >> ~/.bashrc
echo "export LANG=en_US.UTF-8" >> ~/.bashrc
echo "export LC_CTYPE=en_US.UTF-8" >> ~/.bashrc
echo "export LANGUAGE=en_US.UTF-8" >> ~/.bashrc
sudo locale-gen en_US.UTF-8
sudo dpkg-reconfigure locales
# If the server is running some Ubuntu variant:
# Update APT database and install some essentials
sudo apt update
sudo apt install tmux nano wget curl elinks
# Run this command to see the Ubuntu version running:
sudo lsb_release -a
# Run this command to upgrade Ubuntu to newer version:
sudo apt update
sudo apt upgrade
sudo do-release-upgrade
# Now exit the root account using 'exit' command and then re-ssh as 'user'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment