Notes tagged with "Linux"

Install Caddy on Ubuntu VPS

Setting Caddy Up on Ubuntu

  1. First we need to install caddy on the server:
    ```

    sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl

    curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg

    curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list

    sudo chmod o+r /usr/share/keyrings/caddy-stable-archive-keyring.gpg

    sudo chmod o+r /etc/apt/sources.list.d/caddy-stable.list

    sudo apt update
    sudo apt install caddy

    ```

1. Next, let's reconfigure caddy:

    Change /etc/caddy/Caddyfile to read:

    ```json
    {
            log {
                    output file /var/log/caddy/caddy_log.txt
                    level DEBUG
            }
    }
    import sites-enabled/*

    ```

1. Make sure we have a 404 error page:
    
    the Caddyfile should look something like this:
    ```json
    ```
    {
            log {
                    output file /var/log/caddy/caddy_log.txt
                    level DEBUG
            }
           
    }
    
    :443 {
    
            handle_errors {
                header Content-Type text/html
                respond <<HTML
                        <html>
                            <head><title>Oops</title></head>
                            <body>
                                <h5>whoa, we have a problem partner...</h5>
                            </body>
                        </html>
                    HTML 200
            }
    
    }
    import sites-enabled/*
    ```
    ```


1. make sure we have have these directories and that they are owned 
   by the caddy user:

    * /var/log/caddy
    * /etc/caddy/sites-enabled
    * /etc/caddy/sites-disabled

1. restart caddy:

    ```bash
    ... sudo systemctl restart caddy.service
    ```


1. create a new static site file so we can test the setup:


    ```json
    [site-url]  {
            root * /var/www/site_dir
            file_server
    }
    ```
    ```

1. make sure ports 80 and 443 is open on the firewall:


    ```bash
    ... sudo ufw allow http 
    ... sudo ufw allow https 

    ```

Ubuntu VPS Setup

New Ubuntu VPS Set Up

We’ve assuming we’ve created the initial droplet and that we are able to ssh as root into the box. Next steps are as follows:

Add Admin User Account

  1. SSH into the droplet as root:

    Run these commands on the server

    
    # create your admin user
    ... adduser usrnme
    # set up ssh key
    # this was the old way:
    #   ... mkdir /home/usrnme/.ssh
    #   ... chmod 700 /home/usrnme/.ssh
    #   ... cp /root/.ssh/authorized_keys /home/usrnme/.ssh
    #   ... chown -R usrnme:usrnme /home/usrnme/.ssh/authorized_keys
    #   ... chmod 600 /home/usrnme/.ssh/authorized_keys
    # this is shorter and :
    ... rsync --archive --chown=usrnme:usrnme ~/.ssh /home/usrnme
    # add user to sudo
    ... usermod -aG sudo usrnme
    
  2. Install Neovim

file permissions

A note on file permissions.

tmux stuff

N.B. I always reset the tmux command option from ctrl + b to ctrl + a.

Sessions

  • List all tmux sessions: tmux ls or ctrl + a s:
... tmux ls
... 0: 4 windows (created Sat Nov 23 08:44:49 2019) [158x78] (attached)

Windows

  • New Window: ctrl + a n

  • Switch/select window: ctrl + a 0...9

  • Move window: ctrl + a : and :swap-window -t [window-number|+/-move-positions] Swap window: ctrl + a : and :swap-window -s [window-number] -t [window-number]

Linux and My Apple SuperDrive

I have an Apple SuperDrive 2 that would not work on Linux Mint 19. The drive was visible when it plugged it, but would not accept disks. Fortunately I found this article with instruction on how to wake up Apple’s drive and start working.

Here’s the basics:

  1. Install sg3-utils:

    ... sudo apt-get install sg3-utils
    
  2. Find the device id (likely sr0 or sr1). Mine was sr0:

    ... ls -al /dev | grep sr
    lrwxrwxrwx   1 root root           3 Nov 10 11:46 cdrom -> sr0
    lrwxrwxrwx   1 root root           3 Nov 10 11:46 cdrw -> sr0
    lrwxrwxrwx   1 root root           3 Nov 10 11:46 dvd -> sr0
    lrwxrwxrwx   1 root root           3 Nov 10 11:46 dvdrw -> sr0
    brw-rw----+  1 root cdrom    11,   0 Nov 10 11:46 sr0
    
  3. Wake the drive up:

Manage Static Sites

  1. On the server run:

    ... python3.6 nginx_site.py create my.sitename.com
    
  2. Change the access for the root of the site folder so we can easily push changes:

    ... sudo chown user:user /var/www/com_sitename_my
    
  3. Now we can push the static files generated by Pelican to the server:

    # the manual way
    ...  scp -r output/* mark.staticsites:/var/www/thebitsilo_com_notes
    
    # or via pelican
    ... inv publish
    

Linux Server Maintenance

Updating Ubuntu:

```bash
sudo apt update
sudo apt upgrade
sudo apt full-upgrade
sudo apt autoremove

reboot
```

Listing user groups:

```bash
... getent group | sort

```