自動 SSH 登入導致遠端 shell 無回應,傳回客戶端(沒有錯誤)

自動 SSH 登入導致遠端 shell 無回應,傳回客戶端(沒有錯誤)

我在 Ubuntu 14.04 LTS 下使用 Expect 工具時遇到問題。我想自動 ssh 登入某些 Sophos UTM Firewall,並在使用「sudo su -」和正確的密碼後直接提升我的權限。我不必擔心純文字密碼,因為我的腳本直接從 KeePass URL 欄位執行(雙擊執行腳本並透過腳本後面的 agrument/KeePass {Placeholder} 填入正確的密碼)。我設法完成了所有這些工作,除了一個遠端根 shell 之外,它不執行任何命令並「斷開連接」回我的 ubuntu 系統。因此,我嘗試遠端運行的命令在 4-5 秒內沒有執行,然後突然在 ubuntu 系統上執行,並且沒有告訴我發生了什麼。

我需要做什麼才能擁有功能齊全的遠端 shell? SSH 金鑰和直接 root 登入對我來說不是一個解決方案,因為我們有太多的 Sophos UTM。

解釋發生的事情:

sshtool.sh:
#!/usr/bin/expect -f
spawn sshpass -pPASSWORD ssh -t [email protected] "sudo su -"
expect -- "oot's password:"
send "PASSWORD\r"
expect -- "/root #"
expect eof



What happens in the terminal:
vct@vct-virtual-machine:~$ ./sshtool.sh
spawn sshpass -pPASSWORD ssh -t [email protected] sudo su -
root's password:
utm:/root # whoami
# *enter*
# not reacting for 4-5 seconds
vct@vct-virtual-machine:~$ whoami
vct
vct@vct-virtual-machine:~$

像這樣更改腳本並不能解決連線中斷的問題:

sshtool.sh:
#!/usr/bin/expect -f
spawn ssh [email protected]
expect -- "password:"
send "PASSWORD\r"
expect -- "/home/login > "
send -- "sudo su -\r"
expect -- "oot's password:"
send "PASSWORD\r"
expect -- "/root #"
send -- "whoami\r"
expect eof


vct@vct-virtual-machine:~$ ./sshtool.sh
spawn ssh [email protected]
[email protected]'s password:
Last login: Mon Apr 18 09:14:41 2016 from 192.168.1.44


Sophos UTM
(C) Copyright 2000-2015 Sophos Limited and others. All rights reserved.
Sophos is a registered trademark of Sophos Limited and Sophos Group.
All other product and company names mentioned are trademarks or registered
trademarks of their respective owners.

For more copyright information look at /doc/astaro-license.txt
or http://www.astaro.com/doc/astaro-license.txt

NOTE: If not explicitly approved by Sophos support, any modifications
      done by root will void your support.

<M> loginuser@utm:/home/login > sudo su -
root's password:
# Following "whoami" directly executed by the script itself works fine
<M> utm:/root # whoami
root
# After 4-5 seconds, it's dropping the connection again
<M> utm:/root # vct@vct-virtual-machine:~$

先致謝!

答案1

我有一個類似的問題。問題是我的遠端 .bashrc 檔案中有一些行如果不交互運行則不執行任何操作。

相關內容