지정된 user1/클라이언트에서 동일한 user2/서버로의 여러 SSH 액세스 유형

지정된 user1/클라이언트에서 동일한 user2/서버로의 여러 SSH 액세스 유형

user1@cl두 가지 다른 액세스 유형을 사용하여 SSH를 통해 하나의 사용자/클라이언트 조합(예: )에서 사용자/서버 조합(예: )에 액세스하려고 합니다 .user2@srv

  1. 액세스 유형 #1은 Bazaar 저장소와의 상호 작용으로 제한됩니다. 이를 위해 한 줄을 추가했습니다(#1 ~user2/.ssh/authorized_keys).

    command="bzr serve --inet --directory=/repodir --allow-writes",no-port-forwarding,no-X11-forwarding,no-agent-forwarding ssh-rsa ... user1@cl
    
  2. 액세스 유형 #2는 로그인 셸입니다. 이를 위해 ~user2/.ssh/authorized_keys아래와 같이 "일반" 줄(#2)을 추가했습니다.

    ssh-rsa ... user1@cl
    

내가 이해하는 한, 내 테스트에 따르면 두 라인을 동시에 사용할 수 없습니다. 즉, 첫 번째 줄이 나타나면 ~user2/.ssh/authorized_keysbzr 저장소와 상호 작용할 수 있지만 실행할 수는 없습니다.

[user1@cl]$ ssh user2@srv

라인 #2가 먼저 나타나면 ~user2/.ssh/authorized_keys그렇게 할 수 있지만 ssh어떤 bzr작업을 해도

bzr: ERROR: Not a branch ...

이 문제를 해결할 방법이 있나요?

저는 RHEL7을 사용하고 있지만 그건 중요하지 않다고 생각합니다.

관련 게시물(그러나 내가 아는 한 내 상황을 언급하지 않음):

https://stackoverflow.com/questions/2419566/best-way-to-use-multiple-ssh-private-keys-on-one-client

https://serverfault.com/questions/142997/what-options-can-be-put-into-a-ssh-authorized-keys-file

https://serverfault.com/questions/749474/ssh-authorized-keys-command-option-multiple-commands

https://askubuntu.com/questions/1962/how-can-multiple-private-keys-be-used-with-ssh

답변1

  1. 클라이언트 컴퓨터에서 및 user1같은 두 개의 키를 생성합니다 . 특별히 강력한 보안 문제가 없다면 그 중 하나에 대해 빈 비밀번호를 제공할 수 있습니다(예: ) ./home/user1/key1/home/user1/key2key1
  2. 다음 명령을 사용하여 두 키를 모두 서버에 복사합니다 ssh-copy-id.

    ssh-copy-id -i ~/.ssh/key1 [email protected]
    ssh-copy-id -i ~/.ssh/key2 [email protected]
    

    두 가지 모두에 로그인하여 작동하는지 확인하세요.

    ssh -i ~/.ssh/key1 [email protected]
    ssh -i ~/.ssh/key2 [email protected]
    
  3. 서버에서 편집 ~user2/.ssh/authorized_keys하고 command="bzr ..." 첫 번째 키에 추가하세요.

  4. ~user1/.ssh/config파일을 편집 하고 두 키에 대한 별칭을 추가 하려면 클라이언트 컴퓨터로 돌아갑니다 . 이 같은:

    Host alias1
        HostName        server.example.com
        User            user2
        IdentityFile    /home/user1/.ssh/key1
        ControlPath     ~/.ssh/ctl1-%u-%r-%h-%p
        ControlMaster   auto
        ControlPersist  5m
    
    Host alias2
        HostName        server.example.com
        User            user2
        IdentityFile    /home/user1/.ssh/key2
    
  5. 이제 bzr+ssh://alias1for bazaarssh alias2로그인 쉘로 사용하십시오.

~/.ssh/config귀하의 요구 사항, 구문 및 에 맞게 추가로 편집하십시오 /etc/ssh/ssh_config.

답변2

bzrssh작동하도록 두 개의 다른 키 쌍(예: 로그인용 쌍 1, 로그인용 쌍 2)을 사용했습니다 . 에 해당 줄을 추가했습니다 ~user2/.ssh/authorized_keys. 개인 키 1은 file id_rsa(기본 읽기)에 저장되고, 개인 키 2는 file 에 저장됩니다 id_rsa_ssh.

그런 다음 bzr잘 작동하고 로그인하기 위해 다음을 사용합니다.

[user1@cl]$ ssh -i id_rsa_ssh user2@srv

이는 대체 ID의 사용을 제안합니다.

관련 정보