linux配置免密登陸

例如:ubuntu

$ ssh -i ~/ec2.pem ubuntu@12.34.56.78

首先肯定你能夠以密碼的形式鏈接遠程服務器,也能夠建立一個非超級管理員用戶,並增長 sudo 權限

$ sudo ssh root@12.34.56.78

生成 .pem 步驟以下:

1.客戶端(本地主機 )生成驗證沒有密碼密鑰對

$ ssh-keygen -t rsa -b 2048 -v

執行上述命令首先會讓你輸入生成密鑰的文件名:我這裏輸入的 myPemKey ,以後一路回車。ruby

Generating public/private rsa key pair. Enter file in which to save the key (/home/anonymouse/.ssh/id_rsa): myPemKey Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in hetzner. Your public key has been saved in hetzner.pub. The key fingerprint is: bb:c6:9c:ee:6b:c0:67:58:b2:bb:4b:44:72:d3:cc:a5 localhost@localhost The key's randomart image is:

在執行命令的當前目錄下會生成一個myPemKey.pub、myPemKey 兩個文件。bash

2. 把生成的 myPemKey.pub 經過本地命令推送到服務器端,使服務器自動添加認證這個證書

$ ssh-copy-id -i ~/myPemKey.pub root@12.34.56.78

輸入你的 root 用戶密碼服務器

3. 測試鏈接

$ sudo ssh -i ~/myPemKey root@12.34.56.78

或者把 myPemKey 重命名爲 myPemKey.pemdom

$ sudo ssh -i ~/myPemKey.pem root@12.34.56.78

4. 禁用密碼鏈接(注意:要保證 .pem 鏈接成功的狀態下,禁用密碼鏈接)

sudo vi /etc/ssh/sshd_config

找到這一行 #PasswordAuthentication yesssh

# Change to no to disable tunnelled clear text passwords # PasswordAuthentication yes

取消前邊的 # 註釋,改成ide

PasswordAuthentication no

重啓 ssh 服務測試

sudo service ssh restart
相關文章
相關標籤/搜索