參考資料:Google搜尋到的已忘了真正出處了,如有大大知道請告知,小弟再補上,如有侵權,也請告知,小弟將移除

1. Creating authentication key

ssh-keygen生成公/私鑰對:

  beowulf% ssh-keygen -t rsa

  Generating public/private rsa key pair.

  Enter file in which to save the key (/u/kim/.ssh/id_rsa): [RETURN]

  Enter passphrase (empty for no passphrase): 輸入一組安全碼

  Enter same passphrase again: 再輸入一次安全碼

  Your identification has been saved in /u/kim/.ssh/id_rsa.

  Your public key has been saved in /u/kim/.ssh/id_rsa.pub.

  The key fingerprint is:

  b7:18:ad:3b:0b:50:5c:e1:da:2d:6f:5b:65:82:94:c5 kim@beowulf.gw.com

記住你的passphrase(這裡是little lamp jump3d)。其中~/.ssh/id_rsa.pub為公鑰文件

2. Authorizing access 

將公鑰上傳成目標機的~/.ssh/authorized_keys (ftp,scp都可以)

  beowulf% cd ~/.ssh

  beowulf% cp id_rsa.pub authorized_keys

  beowulf% scp -p ~/.ssh/authorized_keys kim@hrothgar:.ssh/

  kim@hrothgar's password: YourPasswordHere

  authorized_keys               100% 1839     1.2MB/s   00:00

其中需要輸入目標機上你的用戶密碼(在此為hrothgar上的kim用戶) 這時,你使用ssh登錄時,將會通過你identificationpassphrase來登錄了。

  beowulf% ssh hrothgar

  Enter passphrase for key '/u/kim/.ssh/id_rsa': 輸入剛設定的安全碼

  kim@hrothgar%

3. Keeping authentication keys in memory

通過ssh-agent來記住認證,添加的方式見下一節。一般的做法是通過ssh-agent來啟動一個shell,在該shell中使用:

  beowulf% ssh-agent $SHELL

  beowulf%

我用的是Debian,在/etc/X11/Xsession.d/下面就又一個90xfree86-common_ssh-agent用於使用ssh-agent來啟動X,這樣,一進入Xssh-agent就是可用的。如果你的系統裡沒有這樣的設置,簡單的做法就是用"ssh-agent startx"來啟動X,如果你用的是xdm,gdm之類的,修改你的~/.xsession文件

4. Managing keys in memory 

通過ssh-add添加keys

  beowulf% ssh-add

  Enter passphrase for /u/kim/.ssh/id_rsa: 輸入剛設定的安全碼

  Identity added: /u/kim/.ssh/id_rsa (/u/kim/.ssh/id_rsa)

然後,你就可以通過

  beowulf% ssh hrothgar

  kim@hrothgar%

ssh登錄而不需要密碼了。


arrow
arrow
    文章標籤
    ssh-agent
    全站熱搜

    天兒啊 發表在 痞客邦 留言(0) 人氣()