Skip to content

Instantly share code, notes, and snippets.

@sri-teja
Last active November 4, 2019 12:13
Show Gist options
  • Save sri-teja/fd98c37e83a3b753b29c8392bf6ff690 to your computer and use it in GitHub Desktop.
Save sri-teja/fd98c37e83a3b753b29c8392bf6ff690 to your computer and use it in GitHub Desktop.
#!/bin/bash
###################################################################
#Note : Use this script at your risk
###################################################################
#Script Name : initial_server_setup.sh
#Description : setup a non root user with name "ubuntu"
## : and give superuser priviliges along with a
## : basic firewall setup
#Args : 1) server public IP Address,
## : 2) path to .pem file
#Usage : bash initial_server_setup.sh
#Author : Sri Teja
#Email : asriteja77712<at>gmail<dot>com
###################################################################
## initial server setup with ubuntu 18.04
echo "Starting..."
## Enter your server public ip in the below line to proceed
## Taking this as first argument
server_public_ip_address = $1
echo "The IP Address you entered is: ${server_public_ip_address}"
## Enter the path to your .pem file to access the server
## Taking this as second argument
path_to_pem_file = $2
echo "The path to .pem file you entered is: ${path_to_pem_file}"
## first login - Login as root
ssh -i $path_to_pem_file root@$server_public_ip_address
## create another user with the name you like
another_user_name = "ubuntu"
adduser $another_user_name
## giving user root privilages through sudo
## Now, when logged in as your regular user,
## you can type sudo before commands to perform
## actions with superuser privileges.
usermod -aG sudo $another_user_name
## Setting Up a Basic Firewall
ufw allow OpenSSH
ufw enable
## exit from the server to login again using non root user
exit
## After this we can use the non root user
## we created above to login by using below command
ssh -i $path_to_pem_file $another_user_name@$server_public_ip_address
echo "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment