[Linux] SSH PEM 免密碼登入指南 (Public Key Authentication)

Intro

X.509標準下我們可以製作PEM私鑰,用以登入放置公鑰的伺服器。


製作流程

1. 當前帳號執行Key產生器

$ ssh-keygen

產生於~/.ssh下:

id_rsa.pub // 公開金鑰(public key)
id_rsa // 私密金鑰(private key)

2. Public Key放至登入伺服器上帳號的~/.ssh/authorized_keys:

ssh user@remotehost 'mkdir -p ~/.ssh;cat >> ~/.ssh/authorized_keys' < ~/.ssh/id_rsa.pub

or

ssh-copy-id -i ~/.ssh/id_rsa.pub user@remotehost

進階用法

  • 其他參數產生鑰匙用法:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com" -f ./your-key-pair
  • 將私鑰轉換為PEM格式 (解決Warning: pem: invalid format):
ssh-keygen -f ~/.ssh/id_rsa -p

Reference

X.509
PEM (Privacy-enhanced Electronic Mail)

Leave a Reply

Your email address will not be published. Required fields are marked *