apt updateapt dist-upgradeapt install unattended-upgradesdpkg-reconfigure --priority=low unattended-upgradesuseradd -m -s /bin/bash jay && passwd jayapt install sudovisudoNow search in this file for groups that can execute sudo commands(groups begin with %) and add your user in that group. Suppose the group name is sudo. Then execute
usermod -aG sudo jaySee the groups for that user to verify
groups jaySwitch to that user
su - jayExecute the following commands on your local linux terminal. Make sure you don't have a key named id_rsa
cd .ssh && ssh-keygenSend the .pub file to the cloud server
ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]Now login to your cloud server disable root login and add a new line for user-ssh-login in the sshd-config
sudo nano /etc/ssh/sshd_configedit PermitRootLogin no and add AllowUsers jay
sudo systemctl restart sshdapt install ufwufw default allow outgoingufw default deny incomingufw allow sshFor Nginx server run
ufw allow "Nginx Full"ufw enablecheck status
ufw statusfor http
ufw allow 80for https
ufw allow 443suppose you have python3.10 then run
apt install python3.10-venvpython3 -m venv venvsource venv/bin/activatewget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bashreload bash
source ~/.bashrcsuppose you want to install lts/iron
nvm install lts/ironYou can also use nvm ls and nvm install v16.20.0
Installing steps on ubuntu 22.04 jammy
sudo apt updatesudo apt install -y apt-transport-https ca-certificates curl gnupgcurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/dockerce.gpgecho "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/dockerce.gpg] https://download.docker.com/linux/ubuntu jammy stable" | sudo tee /etc/apt/sources.list.d/dockerce.list > /dev/nullsudo apt updatesudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -ycreate a service
nano /etc/systemd/system/your_service.service[Unit]
Description=<description about this service>
[Service]
User=<user e.g. root>
WorkingDirectory=<directory_of_script e.g. /root>
ExecStart=<script which needs to be executed>
[Install]
WantedBy=multi-user.targetFor python venv scripts
[Unit]
Description=<project description>
[Service]
User=<user e.g. root>
WorkingDirectory=<path to your project directory containing your python script>
ExecStart=/home/user/.virtualenv/bin/python main.py
# replace /home/user/.virtualenv/bin/python with your virtualenv and main.py with your script
[Install]
WantedBy=multi-user.targetreload daemon
sudo systemctl daemon-reloadManaging services
sudo systemctl start your-service.servicesudo systemctl stop your-service.servicesudo systemctl status your-service.servicesudo systemctl enable your-service.servicesudo systemctl restart your-service.serviceapt install nginxufw allow "Nginx Full"Build the frontend static files and paste that folder(in this case dist) inside /var/www/ Delete the default file inside sites-available and sites-enabled Edit Nginx configuration file
nano /etc/nginx/sites-available/filenameHere is a sample nginx file having both frontend and backend routes set up
server {
listen 80;
# This is for the frontend serving the built files inside /var/www/dist
location / {
root /var/www/dist;
index index.html index.htm;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
try_files $uri $uri/ /index.html;
}
# This is for all the backend routes running on localhost:5000 having routes /question /registration etc.
location /question {
proxy_pass http://127.0.0.1:5000/question;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location /registration {
proxy_pass http://127.0.0.1:5000/registration;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}This assumes backend is running on localhost:5000 and has routes /question /registration. Modify accordingly.
ln -s /etc/nginx/sites-available/filename /etc/nginx/sites-enabled/filenamesystemctl restart nginxapt install certbot python3-certbot-nginxMake sure that Nginx Full rule is available
ufw statuscertbot --nginx -d example.com -d www.example.comLet’s Encrypt’s certificates are only valid for ninety days. To set a timer to validate automatically:
systemctl status certbot.timer