debian_common

This is an old revision of the document!



Enable SSH

Genesis step for all Linux works.


Generate Public/Private key pair

  ssh-keygen -t rsa -b 4096 
  ssh-keygen -t dsa
  ssh-keygen -t ecdsa -b 521
  ssh-keygen -t ed25519
  touch $home/.ssh/authorized_keys 
  chmod 600 $home/.ssh/authorized_keys 

Append public keys for SSH client.


Google Domains with ddclient

Dynamic DNS records are configured in Google Domains, then update IP using ddclient.Set Up Dynamic DNS in Google Domains. Keep generated credentials to use in ddclient.

  sudo apt-get install ddclient 

ddclient and related packages are installed and will pop up the screen to ask a few parameters. Just do it as you wish and exit quickly. This is not your big deal.
Edit /etc/ddclient.conf

  protocol=dyndns2
  ssl=yes
  use=web
  server=domains.google.com
  login=generated_username
  password=generated_password
  your_resource.your_domain.tld 

If this configuration is not work when you run ddclient -noquiet with some WARNINGs because ddclient does not support Google Domains directly. Then change configuration file as followings:

Google Domain protocol is updated, so use it directly.

  protocol=googledomains
  use=web                # this is essential.
  ssl=yes
  login=generated_username
  password=generated_password
  your_resource.your_domain.tld 

Edit sudo crontab -e to run periodically or register as daemon to run start.


Cloudflare with ddclient

Assume you already installed ddclient before this. — Google Domains with ddclient

It require a package libjson-any-perl

  sudo apt-get install libjson-any-perl

edit /etc/ddclient.conf

 ssl=yes
 use=web
 protocol=cloudflare, 				\
 zone=yourhost.com,				\
 login=my-cloudflare-login@email.com,		\
 password=cloudflare-API-global-token		\
 ddns.yourhost.com,

login is email address for Cloudflare and password is API key string. Cloudflare™ with ddclient uses JSON format.

  sudo ddclient -verbos -noquiet 

Run with -verbos and -noquiet option to see the progress. Messages, if any, error(s) show up. add work in crontab with root permission

  sudo crontab -e 
30 */2 * * * /usr/sbin/ddclient -quiet 

This crontab runs at minute 30 past every 2nd hour.


FreeDNS with ddclient

Edit /etc/ddclient.conf

 ssl=yes
 use=web 
 protocol=freedns
 login=login_id
 password='account_password'
 ddns.yourhost.com

Add crontab schedule,

  sudo crontab -e 

Google Domains with API

Create Synthetic record with Dynamic DNS option and keep generated credentials

#!/bin/bash
 
### Google Domains provides an API to update a DNS "Syntheitc record". This script
### updates a record with the script-runner's public IP, as resolved using a DNS
### lookup.
###
### Google Dynamic DNS: https://support.google.com/domains/answer/6147083
### Synthetic Records: https://support.google.com/domains/answer/6069273
 
USERNAME="generated_id"
PASSWORD="generated_password"
HOSTNAME="yoursubdomain.yourdomain.here"
 
# Resolve current public IP
IP=$( dig +short myip.opendns.com @resolver1.opendns.com )
# Update Google DNS Record
URL="https://${USERNAME}:${PASSWORD}@domains.google.com/nic/update?hostname=${HOSTNAME}&myip=${IP}"
curl -s $URL

Cloudflare with API

Getting user's data from Cloudfalre™ Before, you set up the dynamic DNS from Cloudfalre™, you need to set A record with your desired domain name. If you want to use DDNS.DOMAIN.COM as your dynamic DNS. Put A record in DOMAIN.COM section.

curl -X GET 'https://api.cloudflare.com/client/v4/zones/7140bd43dh357d0e8ee2ea786cef70ae/dns_records' \
    -H 'X-Auth-Email: 'YOU@DOMAIN.COM \
    -H 'X-Auth-Key: '8afbeYOUR0API0KEY0INdCLOUDFLARE0 \
    -H 'Content-Type: application/json'

Check your Global API key for X-Auth-Key from My Profiles and Zone ID can be found in your DOMAIN.COM page.

This will shows bunch of strings and just copy them or your can make text file appending » ~/cloudflare.json

To find data you want, you need to arrange using Online JSON parser or your editor. Find out id value for specific domains. Here assume id for ddns.DOMAIN.COM under DOMAIN.COM is 372e679540…86b9e0b59 Make shell script.

#!/bin/sh
 NEW_IP=`curl ifconfig.me/ip`
 CURRENT_IP=`cat /var/tmp/current_ip.dat`
 
  if [ "$NEW_IP" = "$CURRENT_IP" ]
  then
      echo "No Change in IP Adddress"
  else
   curl -X PUT 'https://api.cloudflare.com/client/v4/zones/7140bd43dh357d0e8ee2ea786cef70ae/dns_records/372e679540...86b9e0b59' \
    -H 'X-Auth-Email: 'YOU@DOMAIN.COM \
    -H 'X-Auth-Key: '8afbeYOUR0API0KEY0INdCLOUDFLARE0 \
    -H 'Content-Type: application/json' \
    --data '{
        "type": "A",
        "name": "ddns.domain.com",
        "content": '\"$NEW_IP\"',
        "proxied": true
    }'
   echo $NEW_IP > /var/tmp/current_ip.dat
 fi

grant execute permission

  sudo chmod +x ./ddns.sh

and touch file to record current IP address.

  sudo touch /var/tmp/current_ip.dat

ifconfig.me/ip is API to retrieve external IP for Dynamic DNS. Alternatives are ifconfig.io/ip or api.ipify.org
If your script is /usr/bin/ddns.sh, edit crontab to update IP periodically.

  sudo crontab -e 
  *   */3   *   *   *   /usr/bin/ddns.sh 

Then the script runs every 3 hours.
Júnes's configuration and scripts WebDAV — Updated on 2017/08/24 22:06


Disable / Ignore suspend mode of laptop for lasting online even when LCD lid is closed.

Edit /etc/systemd/logind.conf

 #HandlePowerKey=poweroff  
 #HandleSuspendKey=suspend
 #HandleHibernateKey=hibernate
 #HandleLidSwitch=suspend

Comment out the items that you wish to edit. HandlePowerKey is for when pressing Power key. HandleSuspendKey is for suspend key (if exists). HandleHibernateKey is for hibernation key. And HandleLidSwitch is for lid panel.

 #HandlePowerKey=poweroff  
 #HandleSuspendKey=suspend
 #HandleHibernateKey=hibernate
 HandleLidSwitch=ignore

/etc/X11/xorg.conf.d/disable-gpu.conf
 
Section "Extensions"
    Option "GLX" "Disable"
EndSection

  sudo service stop sshd   # ssd daemon for example 
  /usr/sbin/sshd -d       # need to specify full path 

Find problem from messages in debugging mode.


sudo crontab -e Add command line to find & delete. e.g.) Delete all .nfo file in target directory and its sub-directories at 30 minutes past every 6 hours.

  30 */6 * * * /usr/bin/find /..((your path)).../ -name '*.nfo' -exec rm -f {} \;

Delete empty directory at 30 minutes past every 12 hours

  30 */12 * * * /usr/bin/find /..((your path)).../ -type d -empty -delete

 find . -type f ! -name '*.mkv' -delete

 sudo iwconfig wlan0 power off 

If you don't have .bash_aliases in your home directory.

touch .bash_aliases    

Edit .bash_aliases. Example: Backup Nginx configuration files with date stamp.

alias backup_nginx='sudo rsync -avh --progress /etc/nginx/ /home/user/storage/Nginx.Config//nginx_config_`date +"%Y%m%d"`/'

Rico's cheatsheets – First glimpse on Linux commands

rm

  rm -R			\\ Remove directory, Recursively
  rm -i			\\ Remove with confirmation 
  rm -f			\\ Force deletion of Files Directories 
  rm -v			\\ Show information of deletion process, Verbosely 

ufw (firewalls)

  sudo ufw app list		\\ show app list by firewall 
  sudo ufw allow OpenSSH	\\ allow OpenSSH 
  sudo ufw enable  
  sudo ufw status  

udevadm

To retrieve hardware information such as serial number of product,

  sudo udevadm info --query=all --name=/dev/sda

  • debian_common.1534098086
  • Last modified: 2018/08/12 18:21
  • by Júne Park