Skip to content

Instantly share code, notes, and snippets.

@anistark
Last active January 20, 2025 20:28
Show Gist options
  • Save anistark/2609575a4c5070080da46c4d8c8fc3be to your computer and use it in GitHub Desktop.
Save anistark/2609575a4c5070080da46c4d8c8fc3be to your computer and use it in GitHub Desktop.
Server Setup

Setting up User (for root systems)

Setup New User:

adduser username

Enter a password. (Generate a strong password like: openssl rand -base64 18)

Add user to sudoers group: usermod -aG sudo username

Or Specifying Explicit User Privileges in /etc/sudoers:

Run visudo and add:

root    ALL=(ALL:ALL) ALL
username ALL=(ALL:ALL) ALL

Login with your user and setup ssh key for your user.

If ssh is not installed by default:

sudo apt install openssh-server
sudo systemctl enable --now ssh
sudo systemctl status ssh

sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.initial
sudo nano /etc/ssh/sshd_config

Set PubKeyAuthentication to yes.

sudo systemctl restart ssh

mkdir ~/.ssh
cd ~/.ssh/
touch authorized_keys
vim authorized_keys

Now add your ssh public key. Save and exit. Verify if ssh login via key is working. If yes, good to disable password now.

Disabling Password Authentication on Your Server

sudo vim /etc/ssh/sshd_config

Change:

PasswordAuthentication no

Restart ssh and good to go:

sudo systemctl restart ssh

Setting Up Basic NodeJs Server with Postgres

sudo apt update
sudo apt upgrade
sudo apt install -y vim tree tmux npm git

# NodeJs
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
sudo apt-get install -y nodejs

sudo apt install build-essential
sudo apt update

Setup go:

sudo apt install golang-go
wget -O ~/.tmux.conf https://gist.githubusercontent.com/anistark/1f686bab54e93d1941f9/raw/8962c23f8d897510cce6b9f722a720d53210dcf7/tmux.conf

Setup tmux.conf

Setup bash_profile

source ~/.bashrc
source ~/.bash_profile

Setup Redis.

sudo apt install redis-server -y

Setup NGINX

sudo apt update
sudo apt install nginx
sudo ufw status
sudo systemctl enable nginx

Full Setup NGINX

Setup Postgres

sudo apt install postgresql postgresql-contrib -y
sudo -u postgres psql

Create user with password: CREATE USER ani WITH PASSWORD '123';

Refer Postgres Full Setup

Setup pm2

pm2 start -i 4 --name="appName" npm -- start

Setup forever

forever start app.js

Setup virtualenv

sudo apt update
sudo apt install python-virtualenv

Setup Certbot

sudo apt install certbot python3-certbot-nginx -y

Run Certbot (after app installation):

sudo certbot --nginx

Check certbot autorun: sudo systemctl status certbot.timer Ref Full Setup

Common Errors Encountered:

  • In case of failed install to overwrite a debian package, you have to force overwrite the files causing issues: sudo dpkg -i --force-overwrite <file-path>. Then check if everything is fixed by running: sudo apt-get --fix-broken install Usually might happen for node 18 install. sudo dpkg -i --force-overwrite /var/cache/apt/archives/nodejs_20.5.0-deb-1nodesource1_amd64.deb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment