Basic MySQL status command

MySQL

Basic usage

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# show connection status
status;

# show connections
show processlist;

# show runtime env
SHOW VARIABLES;
SHOW VARIABLES WHERE Variable_name = 'hostname';

# show tables satus
show table status;
show table status where name = 'users';

# show server variables
select @@sql_mode;

# exit
exit;

Nginx password protect through htpasswd

Nginx

Create .htpasswd

1
2
3
4
sudo sh -c "echo -n 'username:' >> /etc/nginx/.htpasswd"
sudo sh -c "openssl passwd -apr1 >> /etc/nginx/.htpasswd"

cat /etc/nginx/.htpasswd # username:$apr1$wI1/T0nB$jEKuTJHkTOOWkopnXqC1d1

Update nginx conf

1
2
3
4
5
6
7
8
server {
listen 80;
...
location / {
auth_basic "Restricted Content";
auth_basic_user_file /etc/nginx/.htpasswd;
}
}

Reload Nginx

1
sudo service nginx reload

Linux Uncomplicated Firewall

Ubuntu

UFW basic usage

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# list allowed ports
sudo ufw status verbose

# show ufw status
sudo ufw status

# show and allow by application name
sudo ufw app list
sudo ufw allow 'Nginx HTTP'
sudo ufw allow 53/tcp
sudo ufw allow 6000:6007/tcp
sudo ufw allow from 8.8.8.8
sudo ufw allow from 8.8.8.8 to any port 22


# show rule raw
sudo ufw show raw

# Default Policies
sudo ufw default deny incoming
sudo ufw default allow outgoing

# service enable
sudo ufw enable

Reference

https://www.digitalocean.com/community/tutorials/how-to-set-up-a-firewall-with-ufw-on-ubuntu-16-04



Docker container startup

Docker

Setup auto startup

1
2
3
4
5
6
7
8
# --restart=always Docker will restart it
docker run --restart=always CONTAINER_ID

# update exisit container
docker update --restart=always CONTAINER_ID
docker update --restart=no CONTAINER_ID

# ps: --restart=always cannot use --rm

Reference

https://docs.docker.com/engine/reference/commandline/run/#options
https://github.com/moby/moby/blob/v1.11.2/docs/reference/commandline/update.md#update-a-containers-restart-policy


Ubunt startup service

Ubuntu

Basic usage

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# List processes
chkconfig --list
systemctl list-units


# Enable / Disable a service - on, off
chkconfig apache on
systemctl enable apache on


# Control a service - start, stop, restart, status
service apache start
systemctl start apache
/etc/init.d/apache start

SSH tunnel

Cli

Usage

1
2
3
4
5
6
7
8
9
# connect port 999 to target.server.tld:3306
ssh target.server.tld -L 999:localhost:3306

sudo ssh -N -f -l user target.server.tld -L 999:localhost:3306

ssh
-N Do not execute a remote command
-f run as background process
-L SSH Tunnel