- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
- Python Advanced Tutorial
- Python - Classes/Objects
- Python - Reg Expressions
- Python - CGI Programming
- Python - Database Access
- Python - Networking
- Python - Sending Email
- Python - Multithreading
- Python - XML Processing
- Python - GUI Programming
- Python - Further Extensions
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 Articles
- what is the simplest way to print a java array
- What's the simplest way to print a Java array?
- What is the best way to get stock data using Python?
- What is the Best Way to Develop Desktop Applications Using Python?
- What is the simplest way to make Matplotlib in OSX work in a virtual environment?
- The simplest way to get the user's current location on Android using Kotlin?
- Simplest way to detect client locale in PHP
- A drum full of kerosene catches fire. What is the simplest way to put off this fire?
- What is the difference between SSH and SFTP?
- How to connect to SSH using PowerShell?
- The simplest way to get the user's current location on Android
- What is the best way to log a Python exception?
- What is the best way to learn Python and Django?
- What's the fastest way to split a text file using Python?