From 2f99e867a1a7233e50b82d1c54812e65dc1482cf Mon Sep 17 00:00:00 2001 From: Manzoor Ahamed Date: Mon, 12 Jul 2021 18:47:56 +0530 Subject: [PATCH] Day 9 Assignment --- 09-check-user-and-perform.py | 11 +++++++++++ 09-ssh-remote-server.py | 25 +++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100755 09-check-user-and-perform.py create mode 100755 09-ssh-remote-server.py diff --git a/09-check-user-and-perform.py b/09-check-user-and-perform.py new file mode 100755 index 0000000..01b4386 --- /dev/null +++ b/09-check-user-and-perform.py @@ -0,0 +1,11 @@ +#!/opt/anaconda3/bin/python + +## Modules +import getpass + +user = getpass.getuser() + +if user == "ahamedm" : + print("I am the admin\nI can install software\nI can create user") +else: + print("I dont have enough permission") diff --git a/09-ssh-remote-server.py b/09-ssh-remote-server.py new file mode 100755 index 0000000..ed77d5c --- /dev/null +++ b/09-ssh-remote-server.py @@ -0,0 +1,25 @@ +#!/opt/anaconda3/bin/python + +## Modules +import getpass +import paramiko + +server = input("Enter the server name : ") +user = input("Enter the user name : ") +passwd = getpass.getpass() + +ssh = paramiko.SSHClient() + +ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) + +## Connect to the server +try: + ssh.connect(hostname=server, username=user, password=passwd) +except: + print("[!] Cannot connect to the SSH Server") + exit() + +## Executing the commands +stdin, stdout, stderr = ssh.exec_command('ls -l') + +print(stdout.read().decode())