[精讚] [會員登入]
3637

[網管心得]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

你可能感興趣的文章

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

How to deal windows10 with lost bootloader issue 如何修復Windows 10 丟失UEFI引導 (bootloader)無法開機

debian安裝drupal細節 設定apache2的細節

在debian9使用apt-key add gpg key from ubuntu keyserver

zfs on ubuntu 20.04 how to destroy zfs pool while error message said pool is busy

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

我有話要說

>>

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

訪客留言

[無留言]

隨機好文

縣市IDP更換SSL憑證及修改servername+wildfly等設定 縣市IDP更換SSL

centos7 apache ssl.conf設定狀況 在apache更新或重啟後可能遇到ssl.conf衝突問題

solution for selinux issue while installing zabbix agent on centos7 install zabbix agent as service will raise selinux issue on some centos 7.3.1611

macbook pro 2019翻蓋就開機問題 macbook automatically boot itself while lifting screen up

踩雷!intellij idea 自動把context都清掉?! iml檔會控制work space context