我尝试过的:
-
invoke_shell()
then channel.send
su
然后发送密码导致不是root
-
invoke_shell()
进而channel.exec_command
导致“通道已关闭”错误
-
_transport.open_session()
then channel.exec_command
导致不是root
-
invoke_shell()
然后写入标准输入并刷新它导致不是 root
看看这个例子:
ssh.connect('127.0.0.1', username='jesse',
password='lol')
stdin, stdout, stderr = ssh.exec_command(
"sudo dmesg")
stdin.write('lol\n')
stdin.flush()
data = stdout.read.splitlines()
for line in data:
if line.split(':')[0] == 'AirPort':
print line
此处找到的示例有更多解释:http://jessenoller.com/2009/02/05/ssh-programming-with-paramiko-completely- Different/ http://jessenoller.com/2009/02/05/ssh-programming-with-paramiko-completely-different/
希望能帮助到你!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)