Last active
February 6, 2025 11:49
-
-
Save mghayour/9138a22ed185ab3d99e840c3895742e6 to your computer and use it in GitHub Desktop.
Auto install and setup rathole client
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Auto install rathole client | |
# Run this with sudo | |
# download it like this: | |
# wget https://gist.githubusercontent.com/mghayour/9138a22ed185ab3d99e840c3895742e6/raw/699a1aca8eca3ec54b632154a22f912338bf7b9a/rathole_auto_install.sh | |
# Ask user for input | |
read -p "Enter rathole remote like domain:port :" remote_addr | |
read -p "Enter rathole service name :" service_name | |
read -p "Enter rathole token :" token | |
# install req | |
apt update | |
apt install wget unzip -y | |
# download rathole | |
if [[ $(uname -m) == "aarch64" ]]; then | |
wget https://github.com/rapiz1/rathole/releases/latest/download/rathole-aarch64-unknown-linux-musl.zip | |
elif [[ $(uname -m) == "x86_64" ]]; then | |
wget https://github.com/rapiz1/rathole/releases/latest/download/rathole-x86_64-unknown-linux-gnu.zip | |
else | |
echo "Not supported" | |
exit 1 | |
fi | |
# install bin | |
unzip rathole-*.zip | |
chmod +x ./rathole | |
mv rathole /usr/local/bin/ | |
rm rathole-*.zip | |
# config | |
mkdir /etc/rathole | |
cat > /etc/rathole/rathole.toml <<EOL | |
# /etc/rathole/rathole.toml | |
[client] | |
remote_addr = "$remote_addr" | |
heartbeat_timeout = 40 | |
[client.services.$service_name] | |
token = "$token" | |
local_addr = "127.0.0.1:22" | |
EOL | |
cat > /etc/systemd/system/rathole.service <<EOL | |
# /etc/systemd/system/rathole.service | |
[Unit] | |
Description=Rathole Client Service | |
After=network.target | |
[Service] | |
Type=simple | |
DynamicUser=yes | |
Restart=on-failure | |
RestartSec=5s | |
ExecStart=/usr/local/bin/rathole -c /etc/rathole/rathole.toml | |
LimitNOFILE=1048576 | |
[Install] | |
WantedBy=multi-user.target | |
EOL | |
# Run service | |
# systemctl restart rathole.service | |
systemctl start rathole.service | |
systemctl status rathole.service | |
systemctl enable rathole.service | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment