Last active
July 17, 2020 11:55
-
-
Save perfecto25/3dea03737df1a6ba092601775ea596f9 to your computer and use it in GitHub Desktop.
Sshuttle
This file contains hidden or 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
[Unit] | |
Description=sshuttle service | |
After=network.target | |
[Service] | |
User=sshuttle | |
Restart=always | |
Type=forking | |
WorkingDirectory=/home/sshuttle | |
ExecStart=/home/sshuttle/sshuttle.sh start | |
ExecStop=/home/sshuttle/sshuttle.sh stop | |
[Install] | |
WantedBy=multi-user.target |
This file contains hidden or 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 | |
config="/home/sshuttle/sshuttle.conf" | |
getPID() { | |
ps -ef | grep "/usr/bin/python /usr/share/sshuttle/main.py" | grep -v grep | awk {'print $2'} | |
} | |
status() { | |
PID=$(getPID) | |
if [[ -n ${PID} ]] | |
then | |
echo "sshuttle is running.." | |
else | |
echo "sshuttle is not running" | |
fi | |
} | |
start() { | |
while read -r line | |
do | |
if [[ -n $line ]] && [[ "${line}" != \#* ]] | |
then | |
rhost=$(echo $line | awk -F',' '{printf "%s", $1}' | tr -d "'") | |
network=$(echo $line | awk -F',' '{printf "%s", $2}' | tr -d "'") | |
if [[ -n $rhost ]] | |
then | |
echo "starting sshuttle over ${rhost} for network: ${network}" | |
nohup sshuttle -r $rhost $network 2>&1 & | |
fi | |
fi | |
done < $config | |
echo "sshuttle running" | |
} | |
stop() { | |
PID=$(getPID) | |
if [[ -n ${PID} ]] | |
then | |
kill -9 $PID | |
echo "sshuttle stopped.." | |
fi | |
} | |
restart() { | |
stop | |
start | |
} | |
case $1 in | |
start|stop|status|restart) "$1" ;; | |
esac | |
exit 0 |
This file contains hidden or 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
sshuttle ALL=(root) NOPASSWD: /usr/bin/python /usr/share/sshuttle/main.py /usr/bin/python --firewall 12*** 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment