

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the simplest way to SSH using Python?
The simplest way to use SSH using python is to use paramiko. You can install it using −
$ pip install paramiko
To use paramiko, ensure that you have correctly set up SSH keys(https://confluence.atlassian.com/bitbucketserver/creating-ssh-keys-776639788.html) on the host machine and when running the python script, these keys are accessible. Once that is done use the following code to connect to a remote server using ssh −
from paramiko import SSHClient ssh = SSHClient() ssh.load_system_host_keys() ssh.connect('user@server:path') ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command('ls') print(ssh_stdout) #print the output of ls command
Running the above code will give you the directory listing on the remote server.
- Related Questions & Answers
- what is the simplest way to print a java array
- What's the simplest way to print a Java array?
- Simplest way to detect keypresses in JavaScript?
- What is the simplest way to make Matplotlib in OSX work in a virtual environment?
- Simplest way to detect client locale in PHP
- The simplest way to get the user's current location on Android using Kotlin?
- What is the difference between SSH and SFTP?
- The simplest way to get the user's current location on Android
- What is the simplest multi-dimensional array in C#?
- What is the best way to log a Python exception?
- How to connect to SSH using PowerShell?
- What is the preferred way to concatenate a string in Python?
- What is the correct way to define class variables in Python?
- What is the best way to handle list empty exception in Python?
- What is the most elegant way to check if the string is empty in Python?
Advertisements