當前位置:首頁 » 操作系統 » linuxrsa

linuxrsa

發布時間: 2025-01-07 03:25:04

linux怎麼用秘鑰登錄

1. 製作密鑰對
在伺服器上製作密鑰對。首先用密碼登錄到你打算使用密鑰登錄的賬戶,然後執行以下命令:
[root@host ~]$ ssh-keygen <== 下面是相應的操作提示,以及密鑰生成的位置都會告訴我們。
Generating public/private rsa key pair.Enter file in which to save the key (/root/.ssh/id_rsa): <== 按 EnterCreated directory '/root/.ssh'.Enter passphrase (empty for no passphrase): <== 輸入密鑰鎖碼,或直接按 Enter 留空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:0f:d3:e7:1a:1c:bd:5c:03:f1:19:f1:22:df:9b:cc:08 root@host

在 當前 用戶的家目錄中生成了一個 .ssh 的隱藏目錄,內含兩個密鑰文件。id_rsa 為私鑰,id_rsa.pub 為公鑰。

2. 在伺服器上安裝公鑰
鍵入以下命令,在伺服器上安裝公鑰:
[root@host ~]$ cd .ssh
[root@host .ssh]$ cat id_rsa.pub >> authorized_keys

如此便完成了公鑰的安裝。為了確保連接成功,請保證以下文件許可權正確:
[root@host .ssh]$ chmod 600 authorized_keys[root@host .ssh]$ chmod 700 ~/.ssh

3. 設置 SSH,打開密鑰登錄功能
編輯 /etc/ssh/sshd_config 文件,添加如下設置:

sudo vi /etc/ssh/sshd_config
RSAAuthentication yesPubkeyAuthentication yes

接著保存後 另外,請留意 root 用戶能否通過 SSH 登錄:PermitRootLogin yes

當你完成全部設置,並以密鑰方式登錄成功後,再禁用密碼登錄:
PasswordAuthentication no

最後,重啟 SSH 服務:
[root@host .ssh]$ service sshd restart

熱點內容
愛豆里的視頻怎麼緩存 發布:2025-02-28 09:33:47 瀏覽:858
境外伺服器和虛擬ip 發布:2025-02-28 09:31:33 瀏覽:655
液晶電視存儲器 發布:2025-02-28 09:23:50 瀏覽:920
學習linux先學什麼 發布:2025-02-28 09:22:16 瀏覽:347
在cmd輸什麼可以查電腦配置 發布:2025-02-28 09:08:25 瀏覽:309
搭建共享文件存儲空間 發布:2025-02-28 09:03:48 瀏覽:825
android線程handler 發布:2025-02-28 09:03:44 瀏覽:408
短鏈接生成源碼 發布:2025-02-28 08:56:43 瀏覽:775
百度音樂上傳 發布:2025-02-28 08:48:39 瀏覽:287
b站漫畫存儲 發布:2025-02-28 08:42:02 瀏覽:966