Posts Tagged ‘ubuntu’

OpenVPN with Ubuntu 20.04 LTS

shtzeng Posted in 系統設定,Tags: , , ,
0

Install Ubuntu 20.04 Server or Desktop

  • Update all packages
    • sudo apt update
    • sudo apt upgrade -y
    • sudo apt dist-upgrade -y
    • sudo apt autoremove
    • sudo shutdown -r now
  • Install easy-rsa for easy setup certifications
    • sudo apt update
    • sudo apt install easy-rsa -y
  • Install OpenVPN
    • sudo apt update
    • sudo apt install openvpn
  • Install OpenVPN with stable version (Option)
    • Ref: https://community.openvpn.net/openvpn/wiki/OpenvpnSoftwareRepos
    • wget -O – https://swupdate.openvpn.net/repos/repo-public.gpg | sudo apt-key add –
    • echo “deb http://build.openvpn.net/debian/openvpn/statble focal main” > /etc/apt/sources.list.d/openvpn-aptrepo.list
    • sudo apt update
    • sudo apt install openvpn
  • Config OpenVPN Server
    • setup certifications using easyrsa for OpenVPN
      • but you can still use openssl command … XD
      • Ref: https://community.openvpn.net/openvpn/wiki/EasyRSA3-OpenVPN-Howto
      • go to /etc/openvpn/ and run `sudo make-cadir easy-rsa`
      • go to easy-rsa dir, you must change to root account or change this dir permission for entry
      • edit vars file, or left default value
      • build require files
        • ./easyrsa init-pki
        • ./easyrsa build-ca
          • it will ask a password for this ca key, please remember it
        • ./easyrsa gen-dh
        • ./easyrsa gen-req openvpn-server nopass
        • ./easyrsa sign-req server openvpn-server
        • ./easyrsa gen-req client-user nopass
        • ./easyrsa sign-req client client-user
        • openvpn –genkey –secret tls-auth.key
      • now, you have files to config OpenVPN Server and Client under /etc/openvpn/ dir
        • easy-rsa/pki/ca.crt
        • easy-rsa/pki/issued/openvpn-server.crt
        • easy-rsa/pki/private/openvpn-server.key
        • easy-rsa/pki/issued/client-user.crt
        • easy-rsa/pki/private/client-user.key
        • easy-rsa/dh.pem
        • tls-auth.key
      • you can copy all of them to /etc/openvpn/ dir for less editing
    • setup OpenVPN config file
      • Ref: https://openvpn.net/community-resources/how-to/
      • back to /etc/openvpn/ dir
      • copy example file for less editing :)
        • cp /usr/share/doc/openvpn/examples/sample-config-files/server.conf.gz ./
        • gunzip server.conf.gz
      • minimal modify server.conf, this section just use ssl certification to auth, if you want user / password for auth, see next part
        • push “redirect-gateway def1 bypass-dhcp”
          • uncomment it for route all traffic to vpn server
        • push “dhcp-option DNS 8.8.8.8”
        • ca ca.crt
        • cert openvpn-server.crt
        • key openvpn-server.key
        • dh dh.pem
        • tls-auth tls-auth.key 0
        • duplicate-cn
        • log-append /var/log/openvpn/openvpn.log
      • add following for user / password auth
        • Ref: https://openvpn.net/community-resources/how-to/#auth
        • use simple script
          • auth-user-pass-verify auth-user.sh via-env
          • script-security 3
          • username-as-common-name
        • use pam
          • auth-user-pass-verify auth-pam.pl via-file
            • auth-pam.pl at /usr/share/doc/openvpn/examples/sample-scripts/auth-pam.pl
            • sudo cp /usr/share/doc/openvpn/examples/sample-scripts/auth-pam.pl /etc/openvpn/
          • script-security 3
          • username-as-common-name
      • now OpenVPN Server configuration completed!
  • Config OpenVPN Client
    • go to /etc/openvpn/
    • copy example files for less editing :)
      • cp /usr/share/doc/openvpn/examples/sample-config-files/client.conf ./
    • mininal modify client.conf
      • Since we want just one config file, remove
        • ca ca.crt
        • cert client.crt
        • key client.key
        • tls-auth ta.key 1
      • Add or Modify
        • remote your-ip/your-fqdn 1194

        • —–BEGIN CERTIFICATE—–
          put your ca.crt content here
          —–END CERTIFICATE—–

        • —–BEGIN CERTIFICATE—–
          put your client-user.crt content here
          —–END CERTIFICATE—–

        • —–BEGIN PRIVATE KEY—–
          put your client-user.key content here
          —–END PRIVATE KEY—–

        • —–BEGIN OpenVPN Static key V1—–
          put you tls-auth.key content here
          —–END OpenVPN Static key V1—–
        • key-direction 1
    • Add for user / password auth
      • auth-user-pass
  • Start OpenVPN
    • check for OpenVPN ‘server.conf’ start at boot
      • sudo systemctl enable openvpn@server
    • start OpenVPN ‘server.conf’
      • sudo systemctl start openvpn@server
  • Ensure NAT traffic route correctly
    • put ip forward for NAT
      • add file /etc/sysctl.d/30-openvpn.conf
        • net.ipv4.ip_forward = 1
      • reload sysctl
        • sudo sysctl -p /etc/sysctl.d/30-openvpn.conf
    • setup iptable for NAT
      • sudo iptables -t nat -A POSTROUTING -s 10.8.0.0/24 ! -d 10.8.0.0/24 -o ens5 -j MASQUERADE
    • save iptable for boot
      • sudo apt-get install iptables-persistent -y
      • sudo iptables-save > /etc/iptables/rules.v4
  • Test for Connect
    • open browser with https://ipinfo.io to check the ip you change to

Ubuntu 更新 ip 的方法

shtzeng Posted in 系統設定,Tags: ,
0

平常裝 server 版本時,
更新 ip 就是去 `/etc/network/interfaces` 更新,
但是裝了 Desktop 版本以後,
發現 `/etc/network/interfaces` 根本是空的,
所以找了一下更新方法。

記得 Desktop 裝好後,會在 Unity 的介面右上角更動網路連線,
所以在 command line 下要改 ip,要去 `/etc/NetworkManager/system-connections/Wired connection X` 更動,
那個 X 只是設定檔的編號,找看看你寫在哪個設定就好~

然後呢,Ubuntu 12.04 更改完儲存馬上就會偵測到然後換 IP 了,ssh 就卡住了 WTF。
而 Ubuntu 16.04 只會在你 stop / start 後才變更,這樣才人性嘛~

記下來,反正下次還是會忘記

date 轉換時間格式在 ubuntu 及 macOS 的不同

shtzeng Posted in 系統設定,Tags: , ,
0

常常用又常常碰壁 = =凸
寫一寫記錄下來

像是 Feb 26 23:59:59 2022 GMT 這串要轉成 unix time stamp 的時候
在 ubuntu 下可以直接用 date --date="Feb 26 23:59:59 2022 GMT" +%s 來轉
在 mac 下就得用 LANG=en_us_8859_1 date -j -f "%b %d %T %Y %Z" "Feb 26 23:59:59 2022 GMT" +%s
對的,因為我 mac 語系是 zh_TW.UTF-8,用來顯示時間的格式不同 zzz
shtzeng@shtzengde-MacBook-Air [~] [16:54:42] $ date "+%b %d %T %Y %Z"
1 31 16:55:44 2020 CST
shtzeng@shtzengde-MacBook-Air [~] [16:55:44] $

所以要帶正確的 LANG 環境變數進去使用

在大陸使用 Ubuntu 安裝套件的加速技巧

shtzeng Posted in Research,Tags: , , , ,
0

在大陸使用 Ubuntu 安裝套件時,
總是會覺得很慢,
慢一下還好,持續的慢就會想殺人了 (遞刀子
不查還好,一查不得了,
cn.archive.ubuntu.com 居然 CNAME 到 us,

;; ANSWER SECTION:
cn.archive.ubuntu.com. 600 IN CNAME us.archive.ubuntu.com.
us.archive.ubuntu.com. 60 IN A 91.189.91.24
us.archive.ubuntu.com. 60 IN A 91.189.91.23
us.archive.ubuntu.com. 60 IN A 91.189.91.26
us.archive.ubuntu.com. 60 IN A 91.189.91.14

然後大陸到 canonical 的 routing 其實也不是很好,
到底~到底~是哪個王八蛋,難道都沒有好用的機器?
網路上找了一下,清華大學開源軟體鏡像站維護的不錯,
這時候去修改 /etc/apt/source.list 把網址都換成 mirror.tuna.tsinghua.edu.cn 就可以了,
跑一次 apt update 把本機的資料庫更新一下,
下載安裝就可以享受到飛快的速度了 ~~~


在處理 python 套件安裝時也一樣悲劇,
這時候就加上 “-i https://pypi.tuna.tsinghua.edu.cn/simple” 參數來加速
像是這樣

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple m3u8

速度馬上就飛起來了

幹,是中國網路太差好嗎 >_<