2017-01-26 42 views
0

我想在多臺計算機上遠程安裝一個寶石,但我得到不同的行爲,當我運行交互(它的工作原理),或當它在批次(拒絕):爲什麼MacOs ssh爲批處理和交互模式提供不同的權限?

$ ssh [email protected] 'gem install iStats' 
Warning: Permanently added '192.168.19.82' (ECDSA) to the list of known hosts. 
ERROR: While executing gem ... (Gem::FilePermissionError) 
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory. 

$ ssh [email protected] 
Warning: Permanently added '192.168.19.82' (ECDSA) to the list of known hosts. 
Last login: Thu Jan 26 10:50:17 2017 from 192.168.21.168 
qa$ gem install iStats 
Building native extensions. This could take a while... 
Successfully installed iStats-1.4.0 
Parsing documentation for iStats-1.4.0 
Done installing documentation for iStats after 0 seconds 
1 gem installed 

qa$ id 
uid=502(qa) gid=20(staff) groups=20(staff),12(everyone),61(localaccounts),79(_appserverusr),80(admin),81(_appserveradm),98(_lpadmin),33(_appstore),100(_lpoperator),204(_developer),395(com.apple.access_ftp),101(com.apple.access_screensharing-disabled),102(com.apple.access_ssh-disabled) 
qa$ logout 
Connection to 192.168.19.82 closed. 

$ ssh [email protected] 'id' 
Warning: Permanently added '192.168.19.82' (ECDSA) to the list of known hosts. 
uid=502(qa) gid=20(staff) groups=20(staff),12(everyone),61(localaccounts),79(_appserverusr),80(admin),81(_appserveradm),98(_lpadmin),33(_appstore),100(_lpoperator),204(_developer),395(com.apple.access_ftp),101(com.apple.access_screensharing-disabled),102(com.apple.access_ssh-disabled) 

我發現,這個作品:

$ echo ' gem install iStats; exit ' | ssh -t -t [email protected] 
Warning: Permanently added '192.168.19.82' (ECDSA) to the list of known hosts. 
Last login: Thu Jan 26 11:40:31 2017 from 192.168.21.168 
qa$ gem install iStats 
Building native extensions. This could take a while... 
Successfully installed iStats-1.4.0 
Parsing documentation for iStats-1.4.0 
Done installing documentation for iStats after 0 seconds 
1 gem installed 
logout 

...但我基於tty的改變在權限驚訝。

這個蘋果是不是很奇怪,或者這是正常的,我錯過了它?

回答

0

在第一個示例中直接運行命令時,shell(默認爲Bash)不會以交互模式運行,該模式會跳過一些初始化腳本,最突出的是~/.bash_profile

現在,如果您通過例如安裝Ruby來安裝Ruby, RVM或rbenv,它很可能不會在這裏找到,因爲這兩個選項都需要更改運行shell的$PATH

因此,當試圖在第一個示例中安裝gem時,嘗試將其全局安裝到系統提供的Ruby中。這要求你是根,這就是爲什麼失敗。

相關問題