I’ve been doing this more than I had expected, which warrants a blog post.
I’m on Windows, so Ansible isn’t really doable.
Securing the server
There’s no 100% security, this is just making attacks harder.
As root
My provider installs AlmaLinux 8 with a custom setup script that I don’t have.
There is no external firewall.
Log in as root:
| |
Change the root password:
| |
Create a new user and allow sudo:
| |
Start a firewall:
| |
I got a warning to disable AllowZoneDrifting, so I did:
| |
Turn passwords and root login off
Edit the SSH config:
| |
Note on SSH ports: I used to change SSH ports, but decided against it after reading this question. But this link tells you how to.
Turn off root login (before-after):
| |
Turn off password authentication:
| |
For some reason GSS-API was on, so I turned it off:
| |
As user
Before restarting sshd, login to another session and copy your public keys:
| |
Set the correct permissions:
| |
Login to yet another session to verify that you can login.
Now’s a good time to try sudo:
| |
Then, verify that:
- you can only login to
dummywith your SSH key. - you cannot login with
ssh dummy@my_ip - you cannot login with
ssh root@my_ip
I then installed oh-my-bash:
| |
For my .bashrc:
| |
Docker
I considered using Podman, but my apps use docker-compose so I don’t want to worry about feature parity.
I’m also not running Docker in Rootless mode for the same reasons.
Install Docker:
| |
Start Docker:
| |
To skip sudo when using Docker:
| |
Then log out and log back in.
Lazydocker
Life is short, so I install lazydocker.
Change the install script so it installs in /usr/local/bin:
| |
Then I execute the script:
| |
Apps
Add a user for qBittorrent to download Ubuntu torrents, and add myself to the group to access files:
| |
Login to a new session and check your groups with groups.
Then, I can copy my docker-compose files over and do:
| |
Backup
For my own reference:
- Stop all containers.
- Delete all large files.
- Copy and paste
~/docker-composeand/home/qbit. - For
/home/qbit, dosudo chmod 770 /home/qbit. - After copying, do
sudo chown -R qbit:qbit qbit/. - Everything should work now.
Cloudflare
My apps are not exposed to the Internet; rather, traffic is forwarded through Cloudflare.
Create a tunnel:
- Log in to Cloudflare One.
- In Networks > Tunnels, Create a Tunnel
- Select Cloudflared
- Choose a name
- Run the “Install and run a connector” command
To add apps:
- Click on the newly created tunnel, select “Edit”.
- In “Public Hostname”, select “Add a public hostname”.
- Subdomain: the subdomain you would like to put the app in.
- Domain: one of your Cloudflare domains
- Path: leave empty
- Type: usually HTTP.
- URL: usually
localhost:[PORT].
- Add the app under Access - Applications.
- Choose “Self-hosted”.
- Use the same subdomain, domain and path as the previous step.
Note: although the connections come into 127.0.0.1, the apps run inside Docker, so those come through whichever IPs Docker assign.
This seems to be 172.18.0.0/24?
Links I looked at
https://www.digitalocean.com/community/tutorials/initial-server-setup-with-centos
https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys-on-centos