what is docker for? How to start with Docker? An example of a web hosting provider.

Duh!

This is not meant to be the thousandth “How To use Docker”. I’m going to write down my experience I’m making with Docker here. Basically, Docker is only one of many container solutions that exist at the moment, the special thing about Docker is its large user base. Similar to the Raspberry Pi, it is by no means the most powerful device, but the large community makes up for it. There are hundreds of explanations and how to’s for every problem, but copy’ n paste is not the right solution for every problem. I write here in the hope that you want to understand what you are doing and not just throw everything into the terminal without thinking about it.

Continue reading

Ufw is for managing a Linux firewall and aims to provide an easy interface to iptables for the user. Install and configure ufw do this as root user or use sudo:

apt install ufw

Set default rules

ufw default deny incoming
ufw default allow outgoing

Allow connections

These commands both allow a connection on port 22 using the TCP protocol. Use one they end up in the same IPtables:

ufw allow ssh
ufw allow 22/tcp

Continue reading

We want to transfer a complete database to another server. All we need is ssh access on both servers. On the old server we start a dump of our database:

mysqldump --single-transaction -h HOSTNAME -u USERNAME -pPASSWORD DATABSE_NAME sqlbkp_`date+"%Y%m%d"`.bak\

Be careful, your password is readable in your bash history. The database is saved as ‘sqlbkp_’ with current date. Now we send the file to the new server into the database:

mysql -h NEW_HOSTNAME -u USERNAME -pPASSWORD DATABASE_NAME < FILE_NAME.bak

Safe all databases in a file per db and gzip that file:

for db in $(mysql -e 'show databases' -s --skip-column-names); do mysqldump $db | gzip > "/backups/mysqldump-$(hostname)-$db-$(date +%Y%m%d).gz"; done

That’s it.

ssh-keygen
defaults to RSA, -t to specifiy the type of key to create, -b to set the key length to 256, 384 or 521 bits

ssh-keygen -t ed25519 -b 521

ssh-copy-id
to copy a ssh key to another server, -i can specify the name of the private key

ssh-copy-id -i <key-name> <host>

ssh-keygen -R
to remove a host from ~/.ssh/known_hosts

ssh-keygen -R <host>

ssh -J
to connect to a server trough one or more jump hosts

ssh -J root@host1.local root@target.local
ssh -J root@host1.local,root@host2.local root@target.local

remote port binding
to bind local port 12345 to remote port 81, -L to , -N to not execute remote command

ssh -N -L 12345:localhost:81 user@target.local

pseudo-terminal allocation
can be used to run a single command like nano or top

ssh -t user@target.local top
ssh -t user@target.local "tail -f /var/log/remote.log"