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"

The purpose of the package unattended-upgrades is to keep your server current with the latest security updates. Or call it automatic updates. Install and configure unattended-upgrades
Do this as root user or use sudo:
apt install unattended-upgrades apt-listchanges

Now configure unattended-upgrades:
dpkg-reconfigure -plow unattended-upgrades

That’s it.

Show a text file and replace text, here: replace foo with bar
sed s/foo/bar/g file.txt

Use ” if your search patterns contains spaces
sed 's/foo foo/bar bar/g' file.txt

Change a text file in place and replace text, here: replace foo with bar
sed s/foo/bar/g file.txt -i

Redirect output to Disk
sed s/foo/bar/g file.txt > newfile.txt

delete 5th line
sed 5d file.text

Delete lines matching ‘foo’
sed /foo/d file.txt

Print line 8
sed -n '8p' file.txt

Print lines 8-10
sed -n '8,10p' file.txt

Append new line containing ‘bar’, after lines containing ‘foo’
sed '/foo/a bar' file.txt

Insert “hello” to the end of line 9
sed 'i9 hello' file.txt

Examples:
sed 's/PermitRootLogin yes/PermitRootLogin no/g' /etc/ssh/sshd_config

http://sed.sourceforge.net/sed1line.txt