"""
Paramiko Module: To login to the machine & executing shell and configuration commands
Paramiko is a python implementation of ssh version-2 protocol,
providing both client & server functionality.
we are using ssh client functonality to access Router & Execute commands.
you can execute some commands or you can transfer some files /folders
from "local to remote" "or" "Remote to local machine"
"""
"""configuration settings to use paramiko
==> Install paramiko module(if it is not installed on your host/machine)
==> Make sure password Authentication is YES in sshd_config file in Remote server
==> Get USERNAME,Password&HOST NAME(IPAddress) of Remote server
==> ssh -i "Devops.pem"ec2-user@ec2-54-87-131-A2.complete-1.amazonaws.com
YES<Enter>
systemctl status sshd<Enter>{active(running)}
sudo vi/etc/ssh/sshd_config<Enter>
{By default pwAuthentication NO Make it YES->save->close}
if you want change/update password->$->sudo password ec2- user <Enter>
You can execute some commands or you can transfer some files/folders from "local to remote"or
"Remote to local Machine" """
import paramiko, json
with open("user_info.json") as info:
data = json.load(info)
# print(data)
user_name = data["user_name_1"]
password = data["password_1"]
IP = data["IP_1"]
# print(user_name, "\n", password,"\n", IP)
ssh_client=paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
print('please wait,executing command on remote server')
ssh_client.connect(hostname=IP,user_name=user_name,password=password)
# # cmd = "ls-lrt/home/narendra/python" #-->gives path related files &folders
print("please wait executing command on remote server ")
stdin,stdout,stderr=ssh_client.exec_command("ls")
print("successfully executed command on remote server")
stdout=stdout.readlins()
print(type(stdout), stdoutAuthor: Boyina Narendra
Supporting Author: M. Meera Sindhu
Request: If you find this information useful, please provide your valuable comments
No comments:
Post a Comment