Skip to content

Instantly share code, notes, and snippets.

@shivampip
Last active November 13, 2019 06:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shivampip/f02e7808c7c32f71ce9bba272592ee2a to your computer and use it in GitHub Desktop.
Save shivampip/f02e7808c7c32f71ce9bba272592ee2a to your computer and use it in GitHub Desktop.
Python SSH Client (Fabric built on top of Paramiko & Invoke)

Fabric is a high level Python (2.7, 3.4+) library designed to execute shell commands remotely over SSH, yielding useful Python objects in return

Installation

pip install fabric

Connect to VPS and Execute commands

from fabric import Connection

host= "153.92.XX.XX"
port= 22
user= "root"
password= "password123"
con= Connection(host, port= port, user= user, connect_kwargs= {"password": password})

def exe(cmd):      
    out= con.run(cmd)
    return out.stdout.strip()
      
while(True):
    cmd= input("$ ")
    out= exe(cmd)

Change directory

with con.cd("/desired/location"):
    out= exe("ls")

Ref

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment