2010-12-08 103 views
5

在沒有用戶交互的情況下(非交互式)在腳本中使用sftp。例如登錄到一個匿名FTP服務器,而不必手動。如何在沒有密碼的情況下使用SSH登錄

+0

你詢問SSH或FTP登錄?問題標題和問題主體似乎有衝突... – Piskvor 2010-12-08 14:23:00

+0

您是否有權訪問服務器?,因爲您需要編輯配置文件。所以它會允許匿名連接。糾正我,如果我錯了。希望這可以幫助。韋斯利。 – Wesley 2010-12-08 14:15:29

+0

4分鐘視頻教程在這裏 - https://www.youtube.com/watch?v=tGwk6zM_NDM – 2016-10-29 17:37:37

回答

12

在您的計算機

cd ~/.ssh 
ssh-keygen -t dsa 

按在每個提示

Generating public/private dsa key pair. 
Enter file in which to save the key (/home/user/.ssh/id_dsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/user/.ssh/id_dsa. 
Your public key has been saved in /home/user/.ssh/id_dsa.pub. 
The key fingerprint is: 
ad:98:43:13:c9:ea:66:8e:d0:d9:66:59:d8:3a:f7:29 
The key's randomart image is: 
+--[ DSA 1024]----+ 
|     | 
|  . .   | 
|  +   | 
|  + . .  | 
| o = S .  | 
| . + = + .  | 
|. o @ = .  | 
| . B oEo .  | 
| . . .o  | 
+-----------------+ 

回車鍵,你將得到2個文件id_dsaid_dsa.pub使用SCP或其他實用程序文件複製到您的服務器

scp ~/.ssh/id_dsa.pub [email protected]:~/.ssh/ 

在您的服務器上

將新密鑰添加到文件〜/ .ssh/authorized_keys中。

cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys 

最後改變接入方式;

chmod 600 ~/.ssh/authorized_keys 
chmod 700 ~/.ssh 

驗證接入模式是正確的〜

ls -ld ~ 

如果沒有,你可以使用

chmod 700 ~ 

糾正你的家庭接入。

註銷並重新登錄

3

要在每次登錄時都不輸入密碼的情況下進行ssh登錄,請將您的公用ssh密鑰附加到目標服務器上的〜/ .ssh/authorized_keys文件中。您可以在〜/ .ssh/id_rsa.pub中找到您的公鑰,或者如果它不存在,您可能需要生成一個。

見詳細的解答,如果你想關閉SFTP問你的文件的每次轉移YES/NO問題,使用您可以使用-n -i命令行參數的FTP腳本文件做FTP時here

0

可能。

ftpscript.in 
----------------- 
user username pwd 
get sourcefile targetfileonlocal 
bye 

然後你可以運行使用ftp -n -i servername<ftpscript.in,以避免讓這個腳本「你想轉移的資源文件?Y/N」之類的問題。要登錄到沒有用戶名,密碼的ftp服務器,那麼服務器ftp需要允許匿名登錄,如Wesley所述。

6

鍵入以下命令

  1. ssh-keygen

    ,直到你得到的提示

  2. ssh-copy-id -i [email protected]_address

    按Enter鍵(這將再次要求t他的主機系統的密碼)

  3. ssh [email protected]_address

    現在,你應該能夠不帶任何口令

相關問題