[精讚] [會員登入]
3455

[網管心得]ssh keygen用法

ssh-copy-id

分享此文連結 //n.sfs.tw/11033

分享連結 [網管心得]ssh keygen用法@外行中的外行
(文章歡迎轉載,務必尊重版權註明連結來源)
2021-04-15 22:20:53 最後編修
2017-05-04 20:59:44 By jung
 

##20171016更新##

之前使用ssh-keygen+local script進行檔案複製及備份,在centos7上遇到

warning message "kex protocol error: type 7" during scp, rsync or shell work

查了一下資料,似乎是sshd的bug問題,在centos上建議修改sshd_config加入

UsePrivilegeSeparation yes

不過使用sftp等連線方式對於較大檔案還是會出現上述"kex protocal error"

最後死心改用rsync,還是報錯,不過rsync會針對失敗檔案進行續傳,不像sftp就直接斷線了,只好全面改用rsync了

但是debain base的ob2d完全沒有這個問題

看來sshd針對不同linux發行版有不同的讀取方式嗎?!

 

############

 

 

為了避免每次重新開伺服器就要重新google一次ssh免密碼登入的用法

所以決定要好好記下來

首先在需要免密碼登入的client機上以將來要登入遠端伺服器的使用者名稱建立keygen相關檔案:id_rsa & id.rsa.pub

command:

user@client:~$ssh-keygen

在產生金鑰的過程中,會詢問一些問題,對於一般的使用者而言,全部都使用預設值(直接按下 Enter 鍵)即可。
Generating public/private rsa key pair.
Enter file in which to save the key (/home/seal/.ssh/id_rsa):
首先指定金鑰儲存的位置,使用預設值即可,直接按下 Enter 鍵。

Enter passphrase (empty for no passphrase):
指定金鑰保護密碼,如果有設定密碼的話,以後每次使用都要輸入密碼,除你需要非常高的安全性,否則就不用設定了,直接按下 Enter 鍵即可。

Enter same passphrase again:
再次輸入密碼,直接按下 Enter 鍵,接著就會產生金鑰了。

Your identification has been saved in /home/seal/.ssh/id_rsa.
Your public key has been saved in /home/seal/.ssh/id_rsa.pub.
The key fingerprint is:
c7:61:98:72:02:91:94:db:12:96:05:9d:59:91:aa:25 seal@seal-desktop
The key’s randomart image is:
+--[ RSA 2048]---+
|   .=O.+oo       |
+------------+

這裡會顯示金鑰的指紋(fingerprint)與 randomart,而產生的金鑰會有兩個檔案:

id_rsa.pub:公開金鑰(public key),這是可以對外公開的金鑰,之後要將它放在遠端的 Linux 伺服器上作認證使用。

id_rsa:私密金鑰(private key),這是要保護好的金鑰,它等同於你的 Linux 密碼,放在自己的電腦中。

###我覺得用ssh-copy-id最不會搞混###

user@client:~$ ssh-copy-id remoteuser@host.ip (remoteuser=遠端登入時要用的使用者帳號)

enter之後會再問一次密碼就完成了Orz

以後從這台client user使用ssh登入遠端主機就不需密碼了

之後有時會遇到虛擬ip改來改去造成ssh登入時金鑰錯誤的狀況

可以用ssh-keygen -f 去掉舊的紀錄

ssh-keygen -f "/home/ubhome/.ssh/known_hosts" -R "192.168.0.11"

 

END

你可能感興趣的文章

設定win10開機自動執行openvpn連接vpn server how to make win10 connecting to a vpn server automactically after booting up

[網管心得]qnap+proxmox 韌體更新及nfs掛載或變更

在windows環境下強制刪除無法以檔案總管刪除的檔案或目錄 how to remove directories or files that cannot be deleted by default file manager

ubuntu18.04網路設定無法啟動問題 network connection failed due to networkmanager settings

啟動chrome時要求須輸入密碼enter password to unlock login keyring asking for entering password to unlock login kerying on Ubuntu desktop

使用bash script 顯示及比較記憶體剩餘用量 How to get the available memory reported as a percentage then compare Numbers and Strings in Linux Shell Script

我有話要說

>>

限制:留言最高字數1000字。 限制:未登入訪客,每則留言間隔需超過10分鐘,每日最多5則留言。

訪客留言

[無留言]

隨機好文

bitbucket repository control application setup 安裝完bitbucket服務後,須設定bitbucket.properties

安裝netbeans9遇到的小狀況 how to show netbeans9 program onto ubuntu desktop

新增IDP程式使用google防機器人的驗證功能 身份認證程式新增google防機器人v2

縣市端新增syncdata spi功能 為了讓部裡主機可以透過OAUTH2流程,呼叫縣市同步SYNCDATA 的API

更新程式環境到wildfly18+openjdk11-phase3: 伺服器環境升級準備 upgrade jdk and wildfly on server