秘鑰加密碼的登入模式

來源:互聯網
上載者:User

標籤:伺服器   private   安全性   public   enter   

應用情境:有時候我們要給遠在北京或者國外的開發人員伺服器的許可權,為了保證伺服器的安全性我們不想讓他們知道伺服器的root登陸密碼,所以我們可以給他們用秘鑰加密碼的登陸模式。

原理:公開金鑰加密 私密金鑰解密。公開金鑰和私密金鑰是成對產生的,所以將私密金鑰發給別人別人也能登陸


用戶端ip:192.168.0.186

伺服器ip:192.168.0.167

1.密鑰認證的產生

[[email protected] .ssh]# ifconfig eth0 | awk  ‘/inet addr/{print }‘

          inet addr:192.168.0.163  Bcast:192.168.0.255  Mask:255.255.255.0


[[email protected] .ssh]# ssh-keygen -t rsa

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa):  #密鑰報存的位置和名稱

Enter passphrase (empty for no passphrase):   #空密碼

Enter same passphrase again: 

Your identification has been saved in /root/.ssh/id_rsa.  # 私密金鑰的位置

Your public key has been saved in /root/.ssh/id_rsa.pub.    # 公開金鑰的位置

The key fingerprint is:

8a:85:d9:37:a8:95:e2:06:0e:d3:18:91:11:60:11:68 [email protected]

The key‘s randomart image is:

+--[ RSA 2048]----+

|BBo              |

|+E               |

|o                |

| +   + o         |

|+ o + * S        |

| + o * o .       |

|  . = .          |

|   .             |

|                 |

+-----------------+


公開金鑰已經產生

現在把公開金鑰上傳到另一台伺服器上去

[[email protected] .ssh]# ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected]:/root/.ssh/

或者使用:

[[email protected] .ssh]# scp id_rsa.pub [email protected]:/root/.ssh/


登陸到伺服器上:

伺服器把用戶端公開金鑰重新命名

[[email protected] .ssh]# mv id_rsa.pub authorized_keys

修改ssh設定檔,設定公開金鑰認證登入

將下邊2行的注釋去掉,重啟ssh服務

RSAAuthentication yes
AuthorizedKeysFile      .ssh/authorized_keys

/etc/init.d/sshd restart

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/49/3E/wKioL1QRVjXwj4VUAAENYwzCf9k114.jpg" title="1.png" alt="wKioL1QRVjXwj4VUAAENYwzCf9k114.jpg" />

配置完畢,現在開始登入一下

[[email protected] .ssh]# ssh 192.168.0.167

Enter passphrase for key ‘/root/.ssh/id_rsa‘: 

Last login: Wed Sep 10 05:20:47 2014 from 192.168.0.186

[[email protected] ~]# 

現在輸入之前設定秘鑰的密碼,就可以登入了。退出登入

[[email protected] ~]# exit
logout
Connection to 192.168.0.167 closed.

linux ssh 密鑰認證和秘鑰密碼即可登入。


當開發人員用完伺服器之後我們在伺服器上刪除公開金鑰即可。開發人員就無法登陸了。

如果其他客戶機也要登陸這台伺服器我們只需要將用戶端的私密金鑰發給其他人就可以登陸了。

是不是很牛逼啊。。。。。


秘鑰加密碼的登入模式

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.