#ssh-keygen -t rsa #直接按 Enter即可

Generating public/private rsa key pair.

Enter file in which to save the key (/home/DEMO/.ssh/id_rsa):

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /home/DEMO/.ssh/id_rsa.

Your public key has been saved in /home/DEMO/.ssh/id_rsa.pub.

The key fingerprint is:15:44:64:ab:23:ca:0b:a1:66:98:5a:4a:83:c3:b4:93 DEMO@test

#這樣會產生 id_rsa和id_rsa.pub 二個檔案:前者是private key後者是:public key.

scp id_rsa.pub username@server_hostname:~/.ssh/ #把id_rsa.pub 放到您要連線電腦的帳號中的.ssh

#cat .ssh/id_rsa.pub >> .ssh/authorized_keys #到您要連線電腦的帳號中的.ssh 把public key加到authorized_keys 這個檔案.之後連線時, 就會用本機的 private key 與遠端電腦的 public key 做認證,這樣就不需輸入帳號密碼, 而且也比較安全.
#注意 ~/.ssh 預設是沒有的,有二個方面可以產生  :第一種是手動建立. 並把目錄屬性更改為 700, 第二種是先用手動ssh到別的主機 ,第一次會有 認證的訊息出來按yes之後 .ssh的目錄就會自己產生了

如果不能連線 請檢查 /var/log/secure  這個 file,是不是有出現這樣的字很

Authentication refused: bad ownership or modes for file /home/xxxxx/.ssh/authorized_keys

如果有請更改下這個指令  chmod 600 ~/.ssh/authorized_keys

arrow
arrow
    全站熱搜

    yuanann 發表在 痞客邦 留言(0) 人氣()