Last active
October 18, 2017 08:23
-
-
Save bobquest33/d7e3914aadda2f7ae09a03b40e29febf to your computer and use it in GitHub Desktop.
fabfile to setup ssh in remote server
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
from fabric.api import * | |
from fabtools import require | |
import fabtools | |
import os | |
import traceback | |
@task | |
def setup_tor_ssh(): | |
require.deb.uptodate_index(quiet=True) | |
# Require tor Debian/Ubuntu packages | |
require.deb.packages([ | |
'tor', | |
]) | |
# Setup the folder where | |
tor_dir = "/var/lib/tor/other_hidden_service" | |
require.directory(tor_dir, owner='debian-tor', use_sudo=True) | |
sudo("chown debian-tor:debian-tor " + tor_dir) | |
service_port = 2122 #Service port to access SSH from client | |
# Ensure hidden service config is in torrc | |
# Copy the torrc file to local to map the Remote Server's SSH port to 2122 | |
local("rm -rf __fab__torrc") | |
get("/etc/tor/torrc", "__fab__torrc",use_sudo=True) | |
with open ("__fab__torrc", 'r') as INF: | |
rc = INF.read() | |
local("rm -rf __fab__torrc") | |
hidden_service_config = "HiddenServiceDir %s\nHiddenServicePort %d 127.0.0.1:22" % (tor_dir, service_port) | |
# Write back the service updated torrc config to server | |
if not hidden_service_config in rc: | |
sudo("echo '%s' >> /etc/tor/torrc" % hidden_service_config) | |
#Restart tor service | |
#sudo('service tor restart') | |
require.service.restart('tor') | |
# Get the service hostname, this will be used to access the hidden service from client | |
tor_hostname = os.path.join(tor_dir, "hostname") | |
tor_host = sudo("cat %s" % tor_hostname) | |
print(tor_host) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment