A command-line script to VPN into PKU’s internal network and seamlessly route traffic through proxy tools like Clash.
Before using the script, ensure you have openconnect
installed on your system.
- macOS:
brew install openconnect
- Linux (Debian/Ubuntu):
sudo apt-get update && sudo apt-get install openconnect
- Linux (Fedora):
sudo dnf install openconnect
- Windows:
- Download and install the official OpenConnect GUI client from here.
- Alternatively, you can use
openconnect
via the Windows Subsystem for Linux (WSL) by following the Linux instructions within your WSL distribution.
- Clone the repository (if you haven't already):
git clone https://github.com/PKUfudawei/pkuvpn.git cd pkuvpn
- Edit
pkuvpn.sh
:- Open the
pkuvpn.sh
script in a text editor. - Follow the comments within the script to replace placeholder values (like
***
) with your PKU username (student ID) and password.
- Open the
Before using the pkuvpn.sh
script for the first time, you must manually connect once to handle initial verification prompts from the PKU VPN service. Open your terminal and run:
sudo openconnect --protocol=pulse https://vpn.pku.edu.cn
Enter your PKU username and password when prompted. Follow any on-screen instructions. Once successfully connected, you can disconnect (usually with Ctrl+C
) and proceed to use the script.
- Navigate to the directory:
Make sure you are in the
pkuvpn
directory where the script is located. - Run the script:
This will initiate the VPN connection and set up the proxy.
./pkuvpn.sh
- Stop the proxy:
Press
Ctrl+C
in the terminal where the script is running.
Once the pkuvpn.sh
script is running and the VPN connection is active, your machine effectively becomes part of the PKU internal network. This allows you to:
- Connect to internal resources via SSH: For example, you can SSH into your lab server which might only be accessible from within the campus network.
ssh your_username@your_lab_server_ip_or_hostname
- Use VS Code Remote Development: Tools like VS Code's Remote - SSH extension will now be able to connect to your lab server or other internal machines seamlessly through the established VPN tunnel.
These are my personal usecases.
To run the script from any directory using a simple command like pkuvpn
:
- Identify your shell configuration file:
- For zsh (common on macOS):
~/.zshrc
- For bash (common on Linux):
~/.bashrc
- For zsh (common on macOS):
- Add the alias:
Open your shell configuration file and add the following line, replacing
/path/to/your/pkuvpn/repo
with the actual absolute path to the directory where you cloned this repository:alias pkuvpn='/path/to/your/pkuvpn/repo/pkuvpn.sh'
- Apply the changes:
Run
source ~/.zshrc
(for zsh) orsource ~/.bashrc
(for bash).
Now you can simply type pkuvpn
in your terminal from anywhere to start the VPN connection.
MIT License