Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

System batch operation and maintenance tool paramiko

Shulou Source: shulou.com Published: 2022-06-03 05:22:54 10月03日 Update

Paramiko is a Python wrapper that implements ssh3 remote secure connections. Support authentication and key mode, can realize remote command execution, file transmission and other functions, compared with pexpect encapsulation level higher security.

1. Paramiko installation

paramiko relies on third-party Ecdsa,Crypto and Python development kits pyhton-devel

Error: command 'gcc' failed with exit status 1 appears when installation appears because there is no Python development kit.

Paramiko has two core classes SSHClient and SFTPClient.

SSHClient is a high-level representation of an SSH server session that encapsulates the transport, channel, and verification and establishment methods of SFTPClient.

2.1>Connect method

connect(self,hostname,port=22,username=None,password=None,pkey=None,key_filename=None,timeout=None,allow_agent=True,look_for_keys=True,compress=False)

pkey: private key method is used for authentication;key_filename is a file name or list of file names used for authentication of private key;allow_agent is set to False to disable linking to ssh proxy;look_for_keys is False to disable searching for private key files in ~/.ssh; compression is turned on when compression is True.

2.2>exec_command

exec_command(self,command,bufsize=-1)

2.3>load_system_host_keys

Load local public key verification file, default is ~/.ssh/known_hosts

load_system_host_keys(self,filename=Noe)

2.4>set_missing_host_key_policy

Set the policy when the connected remote host has no local host key or HostKeys object. Currently, three policies are supported: AutoAddPolicy,RejectPolicy,WarningPolicy.

AutoAddPolicy: Automatically adds host names and host keys to the local HostKeys object and saves them, independent of the configuration of load_system_host_keys()

RejectPolicy: Automatically rejects unknown hostnames and keys, depending on the configuration of load_system_host_keys()

WarningPolicy: A Python warning that logs an unknown host key and accepts it, similar to AutoAddPolicy except that unknown hosts have warning messages.

Tags: Host key file encapsulation tool security object toolkit file name method method identity transfer development support configuration authentication similar advanced two Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi MySQL Shulou Tech Info NVidia Huawei