파일에서 gpg의 비밀번호를 확인하는 방법은 무엇입니까?

파일에서 gpg의 비밀번호를 확인하는 방법은 무엇입니까?

user-id파일에 있는 비밀번호가 맞는지 확인하고 싶어요. 비밀번호를 파일( /home/user/.gpg_pass.txt)에 저장한 후 다음과 같이 사용했습니다.

gpg --verbose --batch --yes --pinentry-mode loopback \
    --passphrase-file=/home/user/.gpg_pass.txt
    --decrypt <file>

이 명령을 사용하기 전에 파일의 비밀번호가 올바르게 입력되었는지 확인하고 싶습니다. 나는 이것을 시도했지만 도움이 되지 않았습니다:

cat /home/user/.gpg_pass.txt | gpg --dry-run --passwd <key_id>


에서 man:gpg

--passwd user-id
       Change the passphrase of the secret key belonging to the certificate 
       specified as user-id.  This is a shortcut for the sub-command passwd  
       of  the edit  key  menu.  When using together with the option --dry-run 
       this will not actually change the passphrase but check that the current 
       passphrase is correct.

내가 입력할 때:

$ gpg --dry-run --passwd <key_id>

비밀번호를 입력하는 동안 다음 창이 두 번 나타납니다. (잘못된 비밀번호를 입력하면 Bad Passphrase (try 2 of 3)GUI 콘솔에 표시됩니다.)

 ┌────────────────────────────────────────────────────────────────┐
 │ Please enter the passphrase to unlock the OpenPGP secret key:  │
 │ "Alper <[email protected]>"                                      │
 │ 3072-bit RSA key, ID 86B9E988681A51D1,                         │
 │ created 2021-12-15.                                            │
 │                                                                │
 │                                                                │
 │ Passphrase: __________________________________________________ │
 │                                                                │
 │         <OK>                                    <Cancel>       │
 └────────────────────────────────────────────────────────────────┘

콘솔 내의 GUI에 비밀번호를 수동으로 입력하는 대신 파이프로 연결하여 gpg --dry-run --passwd <key_id>출력을 반환하여 주어진 비밀번호가 올바른지 확인할 수 있습니다.


관련된:https://stackoverflow.com/q/11381123/2402577

답변1

노력하다

gpg --batch --pinentry-mode loopback --passphrase-file=/home/user/.gpg_pass.txt --dry-run --passwd your-keyid

매뉴얼 페이지에도 나와 있듯이 이는 파일에서 비밀번호를 가져올 수 있는 옵션입니다.

스크립트 내부에서 이 작업을 수행하려면 결과에 따라 반환 코드를 설정한다고 가정하므로 반환 코드를 확인하십시오( 수동으로 확인하려는 경우 $?대부분의 쉘에서 ).echo $?

관련 정보