![]() |
| 密碼學與網路安全一書簡報。 |
建立 RSA 金鑰。
jonny@client:~$ ssh-keygen -t rsa
# PubkeyAuthentication: RSA key for SSH2
Generating public/private rsa key pair. Enter file in which to save the key (/home/jonny/.ssh/id_rsa): Created directory '/home/jonny/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/jonny/.ssh/id_rsa. Your public key has been saved in /home/jonny/.ssh/id_rsa.pub. The key fingerprint is: 37:e7:80:1a:77:fe:85:ea:12:7a:ef:bf:b3:ca:11:b8 jonny@debian The key's randomart image is: +--[ RSA 2048]----+ | | | | | | | o | | . S * . | | +.= * . | | ..E.o o . | | . o. +.. | | . =Bo=+ | +-----------------+# id_rsa.pub = public key.
# id_rsa = private key.
新增 public key 至遠端 Server。
jonny@client:~$ cat .ssh/id_rsa.pub | ssh \
Jonny@Server "cat - >> .ssh/authorized_keys"
# Jonny = user name.
# Server = Domain name or IP address.
接下來可以用 rsync 之類的小程式寫一堆 Shell scripts 來異地備份,凍仁是都會先將 Server 的 $PS1 跟 Client 來點顏色區別,才不會發生關錯機的烏龍事件。
2011-01-05
近來遇到個問題,目錄 $HOME/.ssh/ 必須為 drwx------
檔案 $HOME/.ssh/authorized_keys 必須為 -rw-r--r--
不然在 putty 上會有「Server refused our key」拒絕金鑰的錯誤訊息,至於要不要 restorecon 就不確定了。
預設權限(umask)的部份 CentOS 5 為 0002,而 Debian 6 則是 0022,看出來了嘛?這在手動建立的情形下會差很多!看了下表以後就會知道為什麼 Debian 可以無痛免 key 登入了!
| Type | CentOS | Debian |
| Directory | drwxrwxr-x | drwxr-xr-x |
| File | -rw-rw-r-- | -rw-r--r-- |
相關連結:
★公開鑰匙密碼學與 RSA 簡報 by 密碼學與網路安全
★Debian Reference - 6.9.3. Connecting without remote passwords
★Debian 參考手冊 | 9.5.3 以少許密碼連線 – RSA
★Putty 的 Server refused our key | richliu`s blog
★檔案預設權限:umask | 鳥哥的私房菜

2 Feedback:
謝謝您的寶貴意見,凍仁一定會盡快處理 ~^^