简体   繁体   中英

How to send password while using ssh command in os.system?

For example, I have the code below:

cmd = "ssh <host>"
os.system(cmd)

How I can send the password in the python script so that I don't have to type the password every time?

Use paramiko , like so:

sh = paramiko.SSHClient()
sh.connect(server, username=username, password=password)

There are also many good demos in the paramiko github repo.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM