Skip to content

Instantly share code, notes, and snippets.

@jpigla
Last active May 12, 2021 15:46
Show Gist options
  • Save jpigla/6195f0c7527fb4119ade1652477f5848 to your computer and use it in GitHub Desktop.
Save jpigla/6195f0c7527fb4119ade1652477f5848 to your computer and use it in GitHub Desktop.
Linux Commands saved for later

Linux Commands

System

Update & Upgrade system/server
sudo apt -y update && sudo apt -y upgrade && sudo apt -y dist-upgrade

Reboot server
sudo shutdown -r now

Restart Apache
sudo service apache2 restart

Remove locally downloaded packages and apt-get caches
sudo apt autoremove && sudo apt clean

Add new user
sudo adduser new_user

Grant new user account with administrative privileges (sudo)
sudo usermod -a -G sudo new_user

SSH for new user (If you logged in to your root account using SSH keys, then password authentication is disabled for SSH. You will need to add a copy of your local public key to the new user.)
rsync --archive --chown=new_user:new_user ~/.ssh /home/new_user

Set timezone
sudo timedatectl set-timezone Europe/Berlin

Copy output to clipboard
<command with output> | pbcopy

Rename process
pm2 reload my_current_name --name my_new_name

Add Website to Droplet (DigitalOcean)

If you want to host simple e.g. HTML files (static)

  • sudo mkdir -p /var/www/example.com/html
  • sudo chown -R $USER:$USER /var/www/example.com/html
  • sudo chmod -R 755 /var/www
  • nano /var/www/example.com/html/index.html

Create Server Block File (with app)

  • sudo nano /etc/nginx/sites-available/example.com (and paste/edit codeblock further down)
  • sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
  • sudo nano /etc/nginx/nginx.conf
    • server_names_hash_bucket_size 64; <- uncomment line
  • sudo service nginx restart
server {

    root /var/www/example.com/html;
    index index.html index.htm;

    server_name example.com;

    location / {
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-NginX-Proxy true;
      proxy_pass http://localhost:3000;
      proxy_set_header Host $http_host;
      proxy_cache_bypass $http_upgrade;
      proxy_redirect off;
    }

Installing Certbot

  • sudo add-apt-repository ppa:certbot/certbot
  • sudo apt install python-certbot-nginx
  • sudo ufw allow 'Nginx Full'
  • sudo ufw delete allow 'Nginx HTTP'
  • sudo certbot --nginx -d example.com
  • sudo certbot renew --dry-run

Guides

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment