ssh에서 서버로 로그인하려면 "su username"(암호없이)을 실행하여 해당 사용자 (ssh에서 직접 로그인 없음)로 명령을 실행해야합니다. 내가 paramiko (파이썬)이 작업을 수행하려고했습니다paramiko ssh 연결에서 su user (암호없이) 실행
[email protected]:~# su foo
[email protected]:/root$ cd
[email protected]:~$ ls
: 터미널에서
는이 같은 것
import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('host', username='root', password='mypassword', key_filename='<filename>')
stdin, stdout, stderr = ssh.exec_command('su foo')
print stdout.readlines()
stdin, stdout, stderr = ssh.exec_command('cd')
print stdout.readlines()
stdin, stdout, stderr = ssh.exec_command('pwd')
print stdout.readlines()
ssh.close()
그러나 스크립트는 끝나지 않습니다.
로그는 다음과 같습니다
...
DEB [20111207-16:22:25.538] thr=1 paramiko.transport: userauth is OK
INF [20111207-16:22:25.921] thr=1 paramiko.transport: Authentication (publickey) successful!
DEB [20111207-16:22:25.923] thr=2 paramiko.transport: [chan 1] Max packet in: 34816 bytes
DEB [20111207-16:22:26.088] thr=1 paramiko.transport: [chan 1] Max packet out: 32768 bytes
INF [20111207-16:22:26.088] thr=1 paramiko.transport: Secsh channel 1 opened.
DEB [20111207-16:22:26.151] thr=1 paramiko.transport: [chan 1] Sesch channel 1 request ok
내가에만이 시도하는 경우 :
stdin, stdout, stderr = ssh.exec_command('su foo')
#without print
stdin, stdout, stderr = ssh.exec_command('pwd')
print stdout.readlines()
은 그렇지 foo는 같은 루트로 PWD를 실행합니다.
무엇이 잘못 되었나요?
xx. 내 목표는 su 사용자를 호출 한 다음 cd (자신의 집으로 이동)를 누른 다음 해당 디렉토리에서 svn을 호출하는 것입니다. 이것을 연결하거나 paramiko의 mantain 상태에 연결하는 방법이 있습니까? – apelliciari
'su foo -c "svn up/home/foo"가 하나의 가능성입니다. 이것이 paramiko와는 아무런 관계가 없기 때문에 커맨드 라인에서 먼저 스크립트를 작성하십시오. paramiko에서 "상태를 유지할"수 없다는 것은 아닙니다. 두 개의 독립된 쉘을 실행하고있는 것입니다. – JimB