没有root权限,没有ssh密钥对,又想自动输入密码咋办?
#!/usr/bin/python
# simplest builtin python pseudo-tty for ssh password. meuh
# http://unix.stackexchange.com/a/276385/119298
import os
def run(cmd,*args):
pid, fd = os.forkpty()
if pid==0: # child
os.execlp(cmd,*args)
while True:
data = os.read(fd,1024)
print data
if "password:" in data: # ssh prompt
os.write(fd,"password\n")
elif data.endswith("$ ") or data.endswith("# "): # bash prompt for input
cmd = raw_input() + "\n"
os.write(fd, cmd)
run("ssh", "ssh", "-p", "端口号", "root@10.1.1.1")
/**
*
* __ (__`\
* (__`\ \\`\
* `\\`\ \\ \
* `\\`\ \\ \
* `\\`\#\\ \#
* \_ ##\_ |##
* (___)(___)##
* (0) (0)`\##
* |~ ~ , \##
* | | \##
* | /\ \## __..---'''''-.._.._
* | | \ `\## _.--' _ `.
* Y | \ `##' \`\ \
* / | \ | `\ \
* /_...___| \ | `\\
* / `. | / ##
* | | | / ####
* | | | / ####
* | () () | \ | | _.-' ##
* `. .' `._. |______..| |-'|
* `------' | | | | | || |
* | | | | | || |
* | | | | | || |
* | | | | | || |
* _____ | | | |____| || |
* / `` |-`/ ` |` |
* \________\__\_______\__\
* """"""""" """""""'"""
* Don't be a fucking stupid donkey! No, this is a fucking mule!
*/