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.

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.

General use

Genrate SSH keypair:
ssh-keygen -t ed25519

Remove host from ~/.ssh/known_hosts:
ssh-keygen -R <host>

Copy local ssh-key to another server:
ssh-copy-id <host>

Connect to a server over a jump host – hopping:
ssh -t user@jumphost ssh user@target

update: since OpenSSH 7.3 it is possible to shorten this a bit more:
ssh -J user@jumphost user@target

SSH tunneling

Connect to port 80 on a remote server and build a tunnel to port 8000 on localhost:
ssh -L 8000:localhost:80 server -N

sshfs – mount Remote File Systems

this command mounts a directory from a remote machine into a local directory:
sshfs user@host:/path/on/host /local/path</pre>

X11-Forwarding

must to be enabled in ssh_config and sshd_config:
ssh -X user@server <programm> &

Install packages used by remote machine

ssh remotehost 'dpkg --get-selections' | dpkg --set-selections && dselect install

-N = Do not execute a remote command
-t  = Force pseudo-terminal allocation
-V = Display the version number
-J = This is a shortcut to specify a ProxyJump

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