Thursday 23 January 2020

Connect to Linux/Ubuntu based Remote desktop & execute commands on it using Python

Python  code useful for following :

==> Connect to remote desktop machine(Linux/ Ubuntu based systems) 
==> Copy the files to from local to remote machine 
==> Copy the files to from remote machine to local  machine
==>Executing commands on Remote machine from local machine
==>To take screenshot of remote machine

Note: I have used config.json file, for future modifications

{
  "modelName": "Desktop",
  "Local_Machine_Path": "C:\\Bhagyasree\\images\\",

  "Linux_Remote_Machine_Path": "/home/Narendra/ntest/",
  "Linux_Remote_Machine_IP_Addr": "192.10.14.3",
  "Linux_Remote_Machine_User_Name": "narendrab",
  "Linux_Remote_Machine_Pass_word": "Nanna@786",
}

ip_addr = Linux_Remote_Machine_IP_Addr
User_Name = Linux_Remote_Machine_User_Name
Pass_word = Linux_Remote_Machine_Pass_word
ssh_client = paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
print("Please wait while connecting to host machine/Remote server")
ssh_client.connect(ip_addr, username=User_Name, password=Pass_word)
print("Please wait, executing command on remote machine")

remote_path = Linux_Remote_Machine_Path
local_path = Local_Machine_Path

path = Linux_Remote_Machine_Path
# image_name = "Desktop"

image_name = "Desktop"
cmd1 = "import -window root -display :0 " + path + "{}.png".format(image_name)
stdin, stdout, stderr = ssh_client.exec_command(cmd1)
host = Local_Machine_Path
target = Linux_Remote_Machine_Path
image_name = "Desktop.png"sftp = ssh_client.open_sftp()
sftp.get(target + image_name, host + image_name)
print("file successfully copied")
ssh_client.close()

How to install OpenSSL on CentOS?

How to install latest version of OpenSSL on CentOS?

Step 1:  mkdir Openssl
Step 2:  cd Openssl/
Step 3:  wget https://www.openssl.org/source/old/1.0.2/openssl-1.0.2t.tar.gz
Step 4:  tar -zxvf openssl-1.0.2t.tar.gz
Step 5:  cd openssl-1.0.2t/
Step 6:  ./config --prefix=/usr/ -fPIC -pthread -shared
Step 7:  make all
Step 8:  make install
Step 9:  openssl version