Blog
-
Firefox profile
Here is shortcut i use for my firefox profile
boby@hon-pc-01:~$ cat ~/.local/share/applications/firefox-vpn.desktop [Desktop Entry] Version=1.0 Name=Firefox VPN Comment=Browse the World Wide Web GenericName=Web Browser Keywords=Internet;WWW;Browser;Web;Explorer Exec=firefox -P vpn -private-window --class=Firefox-VPN %u Terminal=false X-MultipleArgs=false Type=Application Icon=go-home Categories=GNOME;GTK;Network;WebBrowser; MimeType=text/html;text/xml;application/xhtml+xml;application/xml;application/rss+xml;application/rdf+xml;image/gif;image/jpeg;image/png;x-scheme-handler/http;x-scheme-handler/https;x-scheme-handler/ftp;x-scheme-handler/chrome;video/webm;application/x-xpinstall; StartupNotify=true Actions=new-window;new-private-window; [Desktop Action new-window] Name=Open a New Window Exec=firefox -P vpn -new-window [Desktop Action new-private-window] Name=Open a New Private Window Exec=firefox -P vpn -private-window boby@hon-pc-01:~$
-
Encrypting a file using OpenSSL
To encrypt a file, run
openssl enc -aes-256-cbc -in FILE -out FILE.enc
To decrypt, use
openssl enc -d -aes-256-cbc -in FILE.enc -out FILE
You can use -k option to provide password in commend line itself so it won’t prompt for password.
Here is a script i use to take backup
boby@hon-pc-01:~$ cat ~/bin/backup-my-files #!/bin/bash cd $HOME/work/ rm -f myfiles.tar.gz myfiles.tar.gz.openssl tar --exclude='MY_FILES/.git' -zcvf myfiles.tar.gz MY_FILES openssl enc -aes-256-cbc -in /home/boby/work/myfiles.tar.gz -out myfiles.tar.gz.openssl echo "Backup available in folder $HOME/work" echo "You can decrypt file using" echo "" echo "openssl enc -d -aes-256-cbc -in myfiles.tar.gz.openssl -out myfiles.tar.gz" boby@hon-pc-01:~$
-
MySQL Unknown collation: utf8mb4_unicode_520_ci
When i restore a MySQL database backup taken on MairaDB 10 on MySQL 5.5, i get error
root@48b55e4d9b35:/home/boby# mysql -u root -pflashwebhost wp < wp.sql ERROR 1273 (HY000) at line 356: Unknown collation: 'utf8mb4_unicode_520_ci' root@48b55e4d9b35:/home/boby#
To fix this, i changed all instance of utf8mb4_unicode_520_ci in the SQL backup file with utf8mb4_unicode_ci with sed.
sed -i 's/utf8mb4_unicode_520_ci/utf8mb4_unicode_ci/g' wp.sql
-
Apache SSL
Here is a non-SSL Apache virtual host.
<VirtualHost *:80> ServerName serverok.in ServerAdmin admin@serverok.in DocumentRoot /home/serverok.in/html CustomLog ${APACHE_LOG_DIR}/serverok.in.log combined <Directory "/home/serverok.in/html"> Options All AllowOverride All Require all granted Order allow,deny allow from all </Directory> </VirtualHost>To convert it to SSL VirtualHost, first change the port to 443
Find
<VirtualHost *:80>Replace with
<VirtualHost *:443>Add the above Directory entry
SSLEngine on SSLCertificateFile /etc/ssl/DOMAIN.crt SSLCertificateKeyFile /etc/ssl/DOMAIN.keyThe resulting VirtualHost will look like
<VirtualHost *:443> ServerName serverok.in ServerAdmin admin@serverok.in DocumentRoot /home/serverok.in/html CustomLog ${APACHE_LOG_DIR}/serverok.in.log combined SSLEngine on SSLProtocol all -SSLv2 -SSLv3 -TLSv1 -TLSv1.1 SSLCertificateFile /etc/ssl/serverok.in.crt SSLCertificateKeyFile /etc/ssl/serverok.in.key <Directory "/home/serverok.in/html"> Options All AllowOverride All Require all granted Order allow,deny allow from all </Directory> </VirtualHost>For added security, you can use the following config
SSLEngine on SSLProtocol all -SSLv2 -SSLv3 -TLSv1 -TLSv1.1 SSLCipherSuite ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:!TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384:!TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256:!DSSEnable mod_ssl
If you get the following error
Invalid command 'SSLEngine', perhaps misspelled or defined by a module not included in the server configurationYou need to enable mod_ssl, to do this, run
On Debian/Apache, run
sudo a2enmod sslRestart Apache
sudo service apache2 restartForce SSL
You can add the following code to Apache virtualhost for the website
Redirect 301 / https://domain.ltd/ -
ping
Ping to Cloud Providers
http://www.gcping.com
https://www.cloudping.info
https://azurespeedtest.azurewebsites.netSpeedtest China
https://perfops.net/ping-from-china – Ping from china.
-
time
- How to set time on Linux Server
- How to sync NTP time with chrony
- How to sync NTP time with systemd-timesyncd
- ntpdate
- Set server time PST/PDT
- Determine the Default Time Zone on Linux
Timestamp in Bash Script
TIME_STAMP="$(date +%Y%m%d-%H%M%S)"for timestamp like 2020-01-23 15:12:45, use
TIME_STAMP="$(date "+%Y-%m-%d %H:%M:%S")"For file name
date +"%Y-%m-%d-%H-%M-%S"Time stamp in PHP
$now = date("Y-m-d-h:i:s");Taking backup
mysqldump -u root -p'mv9wCAcDE3CnBV' serverok_wp > ~/serverok_wp-`date +"%Y-%m-%d-%H-%M-%S"`.sqlAlaram/stopwatch
Time Tracking
-
ntpdate
ntpdate allows you to update server time with ntp servers.
To install, run
apt install ntpdate
To update server time, run
ntpdate ntp.ubuntu.com
Example
root@ip-172-26-2-47:~# ntpdate ntp.ubuntu.com 3 Mar 20:32:54 ntpdate[17295]: adjust time server 91.189.91.157 offset -0.000047 sec root@ip-172-26-2-47:~#
Auto Update Server time with cronjob
Method 1
echo "ntpdate time-a.nist.gov" > /etc/cron.daily/ntpdate chmod 755 /etc/cron.daily/ntpdate
Method 2
Set following cronjob
30 22 * * * /usr/sbin/ntpdate -b -s 1.pool.ntp.org
-
locale-gen
To generate
locale-gen en_US.UTF-8
If you get error setlocale: LC_ALL: cannot change locale
echo "LC_ALL=en_US.UTF-8" >> /etc/environment echo "LANG=en_US.UTF-8" > /etc/locale.conf echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen locale-gen en_US.UTF-8
bash: locale-gen: command not found
bash: warning: setlocale: LC_ALL: cannot change locale
language -
docker search
docker search command allows you to search for images in docker hub.
Example
root@ok:~# docker search nginx NAME DESCRIPTION STARS OFFICIAL AUTOMATED nginx Official build of Nginx. 8043 [OK] jwilder/nginx-proxy Automated Nginx reverse proxy for docker con… 1284 [OK] richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable of… 526 [OK] jrcs/letsencrypt-nginx-proxy-companion LetsEncrypt container to use with nginx as p… 320 [OK] kong Open-source Microservice & API Management la… 160 [OK] webdevops/php-nginx Nginx with PHP-FPM 97 [OK] kitematic/hello-world-nginx A light-weight nginx container that demonstr… 95 bitnami/nginx Bitnami nginx Docker Image 44 [OK] linuxserver/nginx An Nginx container, brought to you by LinuxS… 33 1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5 ubuntu-16-nginx-php-phpmyadmin-mysql-5 26 [OK] tobi312/rpi-nginx NGINX on Raspberry Pi / armhf 18 [OK] wodby/drupal-nginx Nginx for Drupal container image 9 [OK] webdevops/nginx Nginx container 8 [OK] blacklabelops/nginx Dockerized Nginx Reverse Proxy Server. 8 [OK] nginxdemos/nginx-ingress NGINX Ingress Controller for Kubernetes 8 centos/nginx-18-centos7 Platform for running nginx 1.8 or building n… 6 nginxdemos/hello NGINX webserver that serves a simple page co… 4 [OK] 1science/nginx Nginx Docker images that include Consul Temp… 4 [OK] behance/docker-nginx Provides base OS, patches and stable nginx f… 2 [OK] pebbletech/nginx-proxy nginx-proxy sets up a container running ngin… 2 [OK] toccoag/openshift-nginx Nginx reverse proxy for Nice running on same… 1 [OK] travix/nginx NGinx reverse proxy 1 [OK] mailu/nginx Mailu nginx frontend 0 [OK] goodguide/nginx-application-proxy No-configuration Nginx reverse proxy for a R… 0 [OK] ppc64le/nginx Official build of Nginx. 0 root@ok:~#
To see results with 4 or more stars, use
docker search --filter stars=4
-
Docker Login
docker login command allows you to login to docker.com. You need to login to docker before you can upload your own images to docker hub. This is also needed if you need to pull down a private image.
root@ok:~# docker login Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one. Username: serverok Password: Login Succeeded root@ok:~#
if you need to login to a different docker registery, for example your company docker registery, use
docker login IP_OR_HOST_OF_DOCKER_REGISTRY:PORT
To log off, use
docker logout
or
docker logout IP_OR_HOST_OF_DOCKER_REGISTRY:PORT
