Python interacts with SSH

Source: Internet
Author: User

Because the Pexpect module does not work on Windows, it is officially given.

So I used the Paramiko module for our interactions.

My linux is Debian Kali linux 64 bit

First we're going to go into vim 's /etc/ssh/sshd_config and get rid of #PermitRootLogin Without-password. Without-password Change to Yes

Remove #PasswordAuthentication No in front of the line and change no to Yes;

Cause: The Linux security mechanism does not allow the use of root login ssh, and then restart Kali after the change, and open the SSH service.

Service SSH Start

Code Link:

Self-installing Parmiko

Pip Install Parmiko

ImportParmikossh=parmiko. Sshclient ()#Create an ObjectSsh.set_missing_host_key_policy (Parmiko. Autoaddpolicy ())Try: Ssh.connect ("192.168.223.128", 22,"Root","Root")#connection destination, IP, port, Username,passwordexceptException:Print("Not Password Found") Stdin,stdout,stderr=ssh.exec_command ("ifconfig")#This is the command that you want to execute on the target shell after a successful connection forStdinchstdout.readlines ():Print(STD) ssh.close ()

Running the PY

Code map:

Reprint Please note from: This address

Python interacts with SSH

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.