고양이$HOME/.gnupg/gpg-agent.conf

고양이$HOME/.gnupg/gpg-agent.conf

우분투 22.04.1 LTS

다시 시작한 후 작업을 수행 하면 git push REMOTE몇 초 후에 대화 상자가 나타납니다.

+---------------------------------------------------------------+
| Please enter the passphrase to unlock the OpenPGP secret key: |
| "user"                                                        |
| 3072-bit RSA key, ID FF3B0094D97228,                          |
| created 2023-09-22 (main key ID 9BD967C9E4EC49).              |
|                                                               |
|                                                               |
| Passphrase: _________________________________________________ |
|                                                               |
|         <OK>                                   <Cancel>       |
+---------------------------------------------------------------+

수동으로 입력할 필요가 없도록 스크립트를 통해 이 비밀번호를 자동화하려면 어떻게 해야 합니까?

나는 이것을 시도했지만 작동하지 않습니다.

git push REMOTE 
sleep 10  # Waits 10 seconds.
KEY

감사해요!

답변1

첫째: "예상" 방법은 안전하지 않습니다. gpg-agent를 사용하는 것이 좋습니다.

gpg를 사용하는 경우 파일을 복호화/암호화하려고 할 때 gpg-agent를 실행해야 합니다. (git push 시 정확히 무엇을 하려는지 모르겠지만 gpg 파일을 사용하는 것 같습니다.)

편집하다~/.gnupg/gpg-agent.conf

하루 동안의 값은 다음과 같습니다.

default-cache-ttl 86400
max-cache-ttl 86400

이렇게 하면 하루에 한 번만 키를 입력하면 됩니다(또는 처음 누를 때에도 괜찮습니다).

원천: https://superuser.com/questions/624343/keep-gnupg-credentials-cached-for-entire-user-session

완전성을 위해 부팅 세션에 파일 암호 해독, gpg show 또는 이와 유사한 기능을 넣어 키를 한 번만 입력하고 나머지 하루 동안 gpg 에이전트를 활성화할 수도 있습니다.

답변2

이것은 gpg 키의 초기 비밀번호를 캐시하는 방법입니다. 자동화 목적에 맞게 조정할 수 있습니다. 사용해 보았지만 결과 expectgpg-agent없습니다.

터미널 1

  • socat의사 tty를 생성하도록 설정
socat -d -d pty,link=/tmp/socat1,raw,echo=0 pty,link=/tmp/socat2,raw,echo=0
# 2023/12/30 10:53:02 socat[1869865] N PTY is /dev/pts/33
# 2023/12/30 10:53:02 socat[1869865] N PTY is /dev/pts/34
# 2023/12/30 10:53:02 socat[1869865] N starting data transfer loop with FDs [5,5] and [7,7]
  • 이것은 루프로 실행됩니다.

NO2.

  • tty를 내보내고 gpg비밀번호 프롬프트를 생성하는 명령을 실행하십시오. 여기서는 gpg귀하의 경우 git프롬프트를 생성하는 .
export GPG_TTY=/tmp/socat1
gpg -d --homedir $HOME/.gnupg/ --quiet --yes --compress-algo=none --no-encrypt-to --batch --use-agent /path/to/gpgKey.gpg # command to elicit gpg prompt
  • 명령 이 gpg표준 입력을 읽을 때까지 기다리고 있습니다.

터미널 3(선택사항)

file /tmp/socat2
# /tmp/socat2: symbolic link to /dev/pts/34
file /dev/pts/34
# /dev/pts/34: character special (136/34)
cat /tmp/socat2
# Please enter the passphrase to unlock the OpenPGP secret key:
# "REDACTED"
# 4096-bit RSA key, ID REDACTED
# created REDACTED (main key ID REDACTED).
# Passphrase:
  • cat소켓 내용 인쇄 대기가 차단되었습니다.
  • /tmp/socat2링크이고 /dev/pts/34문자 장치이므로 tail종료하는 대신 내용을 인쇄한 후처럼 동작합니다.

제4터미널

  • gpg이전에 실행한 명령 에 비밀번호를 보냅니다 .
cat > /tmp/socat2
# Type your password.
  • 에코를 사용하지 마십시오. 귀하의 비밀번호는 bash 기록에 캐시됩니다.

아니면 Python에서 프로그래밍 방식으로 수행할 수도 있습니다.

import pathlib

with pathlib.Path('/tmp/socat2').open('w', encoding='utf8') as fp:
    fp.write('password\n')

고양이$HOME/.gnupg/gpg-agent.conf

default-cache-ttl 120
max-cache-ttl 999999999
no-allow-external-cache
no-grab

pinentry-timeout 25
pinentry-program /usr/bin/pinentry-tty

관련 정보