[ssh] 비밀번호없이 생성 된 OpenSSH 개인 키에 비밀번호를 추가하려면 어떻게합니까?

puttygen을 사용하여 OpenSSH 개인 키를 생성하고 OpenSSH 형식으로 내보냈습니다. 이 기존 키에 비밀번호를 입력하려면 어떻게해야합니까 (비밀번호로 새 키를 생성하는 방법을 알고 있습니까)?



답변

명령을 시도 ssh-keygen -p -f keyfile

ssh-keygen 매뉴얼 페이지에서

 -p      Requests changing the passphrase of a private key file instead of
         creating a new private key.  The program will prompt for the file
         containing the private key, for the old passphrase, and twice for
         the new passphrase.

 -f filename
         Specifies the filename of the key file.

예:

ssh-keygen -p -f ~/.ssh/id_rsa


답변

ssh-keygen에 -p 옵션을 사용하십시오. 이를 통해 새 키를 생성하지 않고 비밀번호를 변경할 수 있습니다.

sigjuice가 표시하는대로 비밀번호를 변경하십시오.

ssh-keygen -p -f ~/.ssh/id_rsa

필요한 비밀번호는 새 비밀번호입니다. ( ~/.ssh/id_rsa.pubauthorized_keys 파일에 공개 키 를 추가했다고 가정 합니다.) ssh로 테스트하십시오.

ssh -i ~/.ssh/id_rsa localhost

용도에 따라 이름이 다른 여러 개의 키를 가질 수 있습니다.


답변

당신은 또한 사용할 수 있습니다 openssl:

openssl rsa -aes256 -in ~/.ssh/your_key -out ~/.ssh/your_key.enc
mv ~/.ssh/your_key.enc ~/.ssh/your_key
chmod 600 ~/.ssh/your_key

참조 : https://security.stackexchange.com/a/59164/194668


답변