我是新手,通过python使用pexpect模块完整的ssh函数。如你所见,请告诉我ssh命令背后的“-l”用法是什么?似乎-l不是使用ssh的方法。
#!/usr/bin/env python
import pexpect
import sys
host="xxx"
user="xxx"
password="xxxx"
command="ls -l"
child = pexpect.spawn('ssh -l %s %s %s'%(user, host, command)) # what's the usage of "-l" behind ssh? if I remove "-l" , it will come an error.
child.expect('password:')
child.sendline(password)
child.expect(pexpect.EOF)
答案 0 :(得分:0)
根据man ssh
:
-l login_name Specifies the user to log in as on the remote machine. This also may be specified on a per-host basis in the configuration file.
在您的情况下,您可以避免使用-l
:
child = pexpect.spawn('ssh %s@%s %s'%(user, host, command))