顯示具有 ubuntu 標籤的文章。 顯示所有文章
顯示具有 ubuntu 標籤的文章。 顯示所有文章

2024年1月10日 星期三

安裝 ikev2 VPN on Ubuntu 20.04

一、前言:

VPN 主要目的不是要做違法之事, 而是要連往某些有限制拜訪來源或是有安全性限制網域時的橋樑,既然是要連往具有嚴格安全性管制網域自然在 VPN 的通訊協定上必須要使用一種安全性較高的 VPN 協定,傳統的 PPTP/L2TP 雖有安全性,但並不足夠安全。近幾年屬於 IPSec[1] ikev2 (Internet Key Exchange version 2) [2] 是一個較為普及通用的加密的VPN 通訊協定。至於 ikev2 是如何運作, 可以參考 ARAVIND .S 這篇 blog 的介紹[3]

二、安裝 ikev2 VPN server @ Ubuntu 20.04

目前許多作業系統都可以安裝 ikev2 VPN server (包含 windows server [4]), 在此我參考 cloud infrastructure service 這篇文章進行安裝[5]

1.     先更新系統上的 packages 保持在最新的版本
sudo apt-get update
sudo apt-get upgrade

2.     修改 /etc/sysctl.conf IP 能夠做 forward (因為做VPN 就想像是多一張虛擬網卡)editor vi nano 都可以。
sudo nano /etc/sysctl.conf



上面白色字的3行原來是有 mark 註解的,將它們拿掉。

3.     重新啟動 sysctl
sudo sysctl -f

4.     安裝 StrongSwan VPN
支援 ikev2 的服務有很多[2],但目前用的較多的為StrongSwan[6],我們透過 apt-get 安裝它及相關套件。
sudo apt-get install strongswan strongswan-pki libcharon-extra-plugins libcharon-extauth-plugins libstrongswan-extra-plugins libtss2-tcti-tabrmd-dev

5.     安裝憑證授權機構(Certificate Authority, CA)與證書(Certificate)

(1).   產生所需目錄與儲存CA與證書
sudo mkdir -p /root/pki/{cacerts,certs,private}

(2).   產生 root 金鑰以便等會簽署CA
sudo pki --gen --type rsa --size 4096 --outform pem > /root/pki/private/ca-key.pem

(3).   使用上面金鑰產生 root CA
sudo pki --self --ca --lifetime 3650 --in /root/pki/private/ca-key.pem --type rsa --dn "CN=VPN root CA" --outform pem > /root/pki/cacerts/ca-cert.pem

(4).   簽署給 VPN server 用的證書與金鑰
sudo pki --gen --type rsa --size 4096 --outform pem > /root/pki/private/server-key.pem

(5).   使用之前 CA key 簽署 VPN server 證書, IP 用你 VPN server IP(這裏用xxx.xxx.xxx.xxx 取代。
sudo pki --pub --in /root/pki/private/server-key.pem --type rsa | pki --issue --lifetime 1825 --cacert /root/pki/cacerts/ca-cert.pem --cakey /root/pki/private/ca-key.pem --dn "CN=xxx.xxx.xxx.xxx" --san xxx.xxx.xxx.xxx --flag serverAuth --flag ikeIntermediate --outform pem > /root/pki/certs/server-cert.pem

(6).   拷貝所有證書到 /etc/ipsec.d 資料夾
sudo cp -r /root/pki/* /etc/ipsec.d/

6.     設定 StrongSwan VPN server

(1).   將原舊 ipsec.conf 備份
sudo mv /etc/ipsec.conf /etc/ipsec.conf.bak

(2).   新編寫一個 ipsec.conf
sudo nano /etc/ipsec.conf


(3).   編寫 /etc/ipsec.secrets 檔案
sudo nano /etc/ipsec.secrets

(4).  



其中 vpnusername 寫你要使用的帳號名稱
securepassword 寫上你的密碼

(5).   重新啟動StrongSwan 服務
sudo systemctl restart strongswan-starter

(6).   檢測 strongswan 的狀態
sudo systemctl status strongswan-starter

7.     Client 端的使用
在此使用Android StrongSwan 做範例

(1).   先下載你的 VPN 憑證證書到你的手機並導入
    /etc/ipsec.d/cacerts
中的 ca-cert.pem 檔案

(2).   StrongSwan 做設定時輸入你的IP/帳號/密碼外,最重要的是要導入你的VPN 憑證後方可使用




====================================

References

1.     https://en.wikipedia.org/wiki/IPsec , Access on 2024-01-08.

2.     https://en.wikipedia.org/wiki/Internet_Key_Exchange , Access on 2024-01-08.

3.     https://www.linkedin.com/pulse/ikev2-vpn-protocol-explained-what-how-works-aravind-s/ , Access on 2024-01-08.

4.     https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2012-r2-and-2012/hh831807(v=ws.11) , Access on 2024-01-08.

5.     https://cloudinfrastructureservices.co.uk/setup-ikev2-vpn-server-on-ubuntu-20-04/ , Access on 2024-01-08.

6.     https://strongswan.org/ , Access on 2024-01-08.

 

 


2021年9月17日 星期五

How to install XAMPP on Ubuntu

 網路上有許多已寫好的 BLOG, 不再這多寫, 貼上 URL , 各位自行參考

https://vitux.com/ubuntu-xampp/  

如果想要用 panel 方式管理,  sudo 執行 /opt/lampp 下的 manager-linux-x64.run 即可

2021年5月30日 星期日

Ubuntu on Windows 10

 Window 10 提供了直接使用 Linux 系統竹旳介面, 讓你在 windows 環境下同時執行 Linux 的command line 等功能. 

底下的 URL 看一遍應會成功

https://docs.microsoft.com/zh-tw/windows/wsl/install-win10

啟用步驟

1. 要先啟用Windows 子系統 Linux 版選用功能,然後才能在 Windows 10 上安裝任何 Linux 發行版本。

用系統管理員權限執行 power shell , 執行

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart


2. 確認 windows 10 你現在用的版本是新的有支援 WSL2. 若是都有在做更新的這步可省略.

3. 啟用虛擬機功能

  在剛才用系統管理員身份執行的 power shell 中執行

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart


4. 下載 Linux 核心更新套件

    https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi

安裝


5. 將 WSL 2 設為預設版本

wsl --set-default-version 2


6.  執行微軟 store, 尋找 ubuntu, 選擇一個安裝





7. 安裝好, 啟動


8. 設定使用者名稱與密碼, 後完工..