Set Permanently ulimit -n / open files in ubuntu

The currently configured system max can be seen with the command

cat /proc/sys/fs/file-max

This value is the total for the system, not per process.

# available limit
user@ubuntu:~$ ulimit -n
1024

# To increase the available limit to say 65535
user@ubuntu:~$ sudo vim /etc/sysctl.conf

# add the following line to it
fs.file-max = 65535

# run this to refresh with new config
user@ubuntu:~$ sudo sysctl -p
# edit the following file
user@ubuntu:~$ sudo vim /etc/security/limits.conf

# add following lines to it
* soft     nproc          65535    
* hard     nproc          65535   
* soft     nofile         65535   
* hard     nofile         65535
root soft     nproc          65535    
root hard     nproc          65535   
root soft     nofile         65535   
root hard     nofile         65535

# edit the following file
user@ubuntu:~$ sudo vim /etc/pam.d/common-session
# fedora => /etc/pam.d/login

# add this line to it
session required pam_limits.so

# logout and login and try the following command
user@ubuntu:~$ ulimit -n
65535

References
https://medium.com/@muhammadtriwibowo/set-permanently-ulimit-n-open-files-in-ubuntu-4d61064429a
https://askubuntu.com/questions/1110544/what-is-the-maximum-recommended-number-of-open-file-descriptors-on-my-vmware-whi

Install Shadowsocks with v2ray-plugin

sudo apt-get update && sudo apt-get upgrade -y && sudo apt-get dist-upgrade -y && sudo apt-get autoremove -y && sudo apt-get clean && sudo apt-get install build-essential haveged -y
## Ubuntu 18.04/16.04 or Debian 9
wget -O ubuntu-ss-install.sh https://github.com/M3chD09/shadowsocks-with-v2ray-plugin-install/raw/master/ubuntu-ss-install.sh
chmod +x ubuntu-ss-install.sh
./ubuntu-ss-install.sh
# Manage shadowsocks with systemctl
systemctl status shadowsocks
systemctl start shadowsocks
systemctl stop shadowsocks
nano /etc/shadowsocks-libev/config.json
{
    "server":"0.0.0.0",
    "server_port":80,
    "password":"PASSWORD",
    "timeout":300,
    "user":"nobody",
    "method":"aes-256-gcm",
    "nameserver": "8.8.8.8",
    "fast_open":true,
    "reuse_port":true,
    "no_delay":true,
    "plugin":"/etc/shadowsocks-libev/",
    "plugin_opts":"server"
}

References
https://github.com/M3chD09/shadowsocks-with-v2ray-plugin-install
https://gist.github.com/rampageX/134fa08a547d4b1eabd754c279b12676

Run a Tor Bridge on Ubuntu

RunAsDaemon 1
BridgeRelay 1
ORPort 16001
ServerTransportPlugin obfs4 exec /usr/bin/obfs4proxy
ServerTransportListenAddr obfs4 0.0.0.0:16002
ExtORPort auto
ContactInfo [email protected]
Nickname yourNickname
PublishServerDescriptor 0

References
https://community.torproject.org/relay/setup/bridge/debian-ubuntu/
https://scottlinux.com/2016/01/16/how-to-run-a-tor-bridge-on-linux/
https://tails.boum.org/doc/first_steps/startup_options/bridge_mode/index.en.html

Execute a command whenever a file changes

You can do this with inotifywait utility from inotify-tools package

while true ; do
  inotifywait -e delete_self "/tmp/fileToMonitor.txt" \
    && cp new_file "/tmp/fileToMonitor.txt"
done
[ "$UID" -eq 0 ] || exec sudo "$0" "$@"

while true ; do
  inotifywait -e modify "/etc/resolv.conf" && ./dns.sh
done

References
https://superuser.com/questions/939600/how-to-get-notified-when-a-specific-file-is-deleted-in-linux
https://superuser.com/questions/181517/how-to-execute-a-command-whenever-a-file-changes
http://man7.org/linux/man-pages/man1/inotifywait.1.html#EVENTS