키체인 설치 및 수동 실행

키체인 설치 및 수동 실행

(및 관련 도구) 작업을 수행할 때 암호로 보호된 SSH 키를 사용하고 싶습니다 parallel-ssh. 그러나 나는 이것을 작동시킬 수 없습니다.

에 관한 모든 문서에서는 다음을 사용 하거나 수행 parallel-ssh할 수 있어야 함을 보여줍니다 .--askpass-A

-A
--askpass
      Prompt  for  a  password  and pass it to ssh.  The password may be 
      used for either to unlock a key or for password authentication.  The 
      password is transferred in a fairly secure manner (e.g., it will not 
      show up in argument lists).  However, be aware that a root user on 
      your system could potentially intercept the password.

그러나 키의 암호를 입력하면 작동하지 않습니다.

$ parallel-ssh --hosts=machines --user=my_user --askpass \
    --timeout=0 --inline -v 'sudo apt-get update'
Warning: do not enter your password if anyone else has superuser
privileges or access to your account.
Password: 
[1] 09:59:36 [FAILURE] amritiii Exited with error code 255
Stderr: Enter passphrase for key '/home/nhaigh/.ssh/id_rsa': 
Permission denied (publickey,password).
[2] 09:59:37 [FAILURE] gbdev Exited with error code 255
Stderr: Enter passphrase for key '/home/nhaigh/.ssh/id_rsa': 
Permission denied (publickey,password).
[3] 09:59:37 [FAILURE] code Exited with error code 255
Stderr: Enter passphrase for key '/home/nhaigh/.ssh/id_rsa': 
Permission denied (publickey,password).
[4] 09:59:37 [FAILURE] apollo Exited with error code 255
Stderr: Enter passphrase for key '/home/nhaigh/.ssh/id_rsa': 
Permission denied (publickey,password).
[5] 09:59:37 [FAILURE] odin Exited with error code 255
Stderr: Enter passphrase for key '/home/nhaigh/.ssh/id_rsa': 
Permission denied (publickey,password).
[6] 09:59:37 [FAILURE] hathor Exited with error code 255
Stderr: Enter passphrase for key '/home/nhaigh/.ssh/id_rsa': 
Permission denied (publickey,password).
[7] 09:59:37 [FAILURE] ldap Exited with error code 255
Stderr: Enter passphrase for key '/home/nhaigh/.ssh/id_rsa': 
Permission denied (publickey,password).
[8] 09:59:37 [FAILURE] thor Exited with error code 255
Stderr: Enter passphrase for key '/home/nhaigh/.ssh/id_rsa': 
Permission denied (publickey,password).
[9] 09:59:37 [FAILURE] bioserver Exited with error code 255
Stderr: Enter passphrase for key '/home/nhaigh/.ssh/id_rsa': 
Permission denied (publickey,password).

내 SSH 키와 암호 문구가 각 컴퓨터에서 작동한다는 것을 확인했기 때문에 이 작업을 수행하는 방법을 모르겠습니다.

답변1

와 가 동등하다고 가정하면 parallel-ssh스위치 pssh를 사용할 때 암호를 파이핑하면 제대로 작동할 것입니다 -A.

다음은 2 개의 서로 다른 시스템에 연결하는 예입니다 host1. 의 기본 사용자를 제공하기 위해 스위치를 host2사용합니다 . 그러나 호스트 이름 을 .-lpsshroothost2-Huser1@host2

$ pssh -A -i -H "host1 user1@host2" -l root 'echo "hi"'
Warning: do not enter your password if anyone else has superuser
privileges or access to your account.
Password: 
[1] 21:38:00 [SUCCESS] user1@host2
hi
Stderr: 
This is a private site.  Unauthorized connections are prohibited.  
All activity may be logged.  Disconnect immediately if you object to 
this policy or are not an authorized user.

X11 forwarding request failed on channel 1
Killed by signal 1.
[2] 21:38:00 [SUCCESS] host1
hi
Stderr: 
This is a private site.  Unauthorized connections are prohibited.  
All activity may be logged.  Disconnect immediately if you object to 
this policy or are not an authorized user.

ControlSocket /home/user1/.ssh/[email protected]:22 already exists, disabling multiplexing
X11 forwarding request failed on channel 0
Killed by signal 1.

위의 작업이 작동하면 내가 실행 중인 명령의 출력이 표시됩니다 echo "hi".

귀하의 문제

SSH 키 쌍의 암호와 관련하여 발생하는 문제는 버그로 인한 것입니다. 이것은 제목이 다음과 같은 버그입니다.문제 80: 암호를 전달하지 않습니까?. 해당 문제에 대한 네 번째 의견에는 패치가 나와 있습니다.

발췌

#4[이메일 보호됨]

나는 그 줄을 다음과 같이 바꿨다.

  if not ( prompt.strip().lower().endswith('password:') or 
        'enter passphrase for key' in prompt.strip().lower()):

그리고 효과가 있는 것 같아

참고자료

답변2

keychain수동으로 패치하는 대신 설치하여 이 작업을 수행할 수 있었습니다.벌레내 문제를 일으키는.

키체인 설치 및 수동 실행

# install keychain package
$ sudo apt-get install keychain

# add my key to the keychain, entering passphrase when asked
$ keychain ~/.ssh/id_rsa

# source the file generated by the above command
$ . ~/.keychain/$(uname -n)-sh

비밀번호/암호 입력 없이 명령 실행

parallel-ssh이제 이번에는 키체인이 인증을 처리하므로 호출할 때 암호가 필요하지 않습니다 .

$ parallel-ssh --hosts=machines --user=my_user --timeout=0 'sudo apt-get update'
[1] 14:52:15 [SUCCESS] amritiii 
[2] 14:52:17 [SUCCESS] odin
[3] 14:52:25 [SUCCESS] gmod
[4] 14:53:11 [SUCCESS] bioserver
[5] 14:53:14 [SUCCESS] thor
[6] 14:53:14 [SUCCESS] apollo
[7] 14:53:16 [SUCCESS] gbdev
[8] 14:53:17 [SUCCESS] code
[9] 14:53:18 [SUCCESS] hathor
[10] 14:53:34 [SUCCESS] ldap

로그인 시 키체인 실행

수동으로 실행하여 키체인에 키를 추가할 필요 없이 다음을 키체인 끝에 추가하기만 하면 됩니다 ~/.bash_profile.

$ keychain --clear $HOME/.ssh/id_rsa
$ . $HOME/.keychain/$(uname -n)-sh

이렇게 하면 재부팅 후 처음 로그인할 때 키의 암호를 입력하라는 메시지가 표시됩니다. 그러면 키는 다음 재부팅 때까지 키체인에 유지되거나 수동으로 키체인을 지울 수 있습니다.

키체인을 사용한 크론 작업

위 내용을 파일에 입력하면 ~/.bash_profilecronjob이 실행되기 전에 동일한 파일을 저장하여 이제 키가 키체인에 저장된다는 사실을 활용할 수 있습니다. 예를 들어 매일 밤 21시에 실행되고 SSH를 통해 원격 컴퓨터에 내용을 복사하는 백업 스크립트가 있습니다. 이것은 내 crontab( crontab -e) 의 항목입니다 .

 0 21 * * * . $HOME/.keychain/$(uname -n)-sh; $HOME/backup_script.sh

답변3

사용SSH 에이전트자동으로 인증합니다(새 쉘에 에이전트 환경 변수를 설정하려면 쉘 이름을 인수로 사용). 다음을 사용하여 키를 추가하세요.SSH 추가비밀번호를 한 번만 입력하세요.

$ ssh-agent bash
$ ssh-add
Enter passphrase for /xxxx/.ssh/identity: 
$ 
$ pssh ...

관련 정보