2013-03-11 26 views
0

我想用另一個用戶名寫一個shell腳本以ssh到另一個unix服務器。 我使用的Unix服務器是SunOS。使用其他名稱在另一臺服務器上登錄的shell腳本

我已經嘗試了許多選項,如期望工具和sshpass,但他們都沒有工作,有人可以幫我使用sshpass的腳本,因爲我聽說它提供了一個安全的登錄。

+0

可能重複[ssh到另一臺服務器,並列出目錄中的目錄](http://stackoverflow.com/questions/15652387/ssh-to-another-server-and-list-only-the-directories -inside-a-directory) – 2013-04-17 04:32:56

回答

2

如果你是在本地主機用戶bob,並希望sshsunmachine作爲fred你會怎麼做:

$ ssh [email protected] 

這將讓您登錄到sunmachinefred,不bob

您還可以使用配置文件~/.ssh/config設置別名:

Host sun 
Host sunmachine.domain.co.uk 
User fred 

現在,您只需鍵入(任何用戶)

$ ssh sun 
# ssh [email protected] <- the un-aliased command that is run 

注:設置key based authenitication所以你不會提示您輸入密碼。

+0

我需要一個自動發送密碼的shell腳本,我可以使用用戶名fred登錄到sunmachine.domain.co.uk,而無需使用服務器進行干預。 – Utsav 2013-03-11 13:45:58

+0

然後你想使用[key based authenitication](http://www.thegeekstuff.com/2008/07/ssh-key-based-authentication-setup-from-openssh-to-ssh2/)! – 2013-03-11 13:47:25

+0

我不是超級用戶,我不認爲我有這樣做 – Utsav 2013-03-11 13:53:13

相關問題