1
當我從一臺服務器到另一臺服務器執行一個簡單的ssh(使用終端)時,它運行良好,但是當我嘗試使用pexpect模塊從我的python應用程序使用ssh時,這樣做。任何想法爲什麼發生這種情況?獲取從pexpect python模塊執行ssh時的權限
Traceback (most recent call last):
File "pef.py", line 8, in <module>
s.login(hostname, username, password)
File "/usr/local/pythonbrew/pythons/Python-2.7.10/lib/python2.7/site-packages/pexpect/pxssh.py", line 316, in login
raise ExceptionPxssh('permission denied')
pexpect.pxssh.ExceptionPxssh: permission denied
我使用Pexpect的文檔
from pexpect import pxssh
import getpass
s = pxssh.pxssh()
s.force_password = True
hostname = raw_input('hostname: ')
username = raw_input('username: ')
password = getpass.getpass('password: ')
s.login(hostname, username, password)
s.sendline('uptime') # run a command
s.prompt() # match the prompt
print(s.before) # print everything before the prompt.
s.sendline('ls -l')
s.prompt()
print(s.before)
s.sendline('df')
s.prompt()
print(s.before)
s.logout()