
~/.ssh/
내 SSH ID 파일을 내 폴더 에 넣어 왔습니다 . 아마 거기에 약 30개의 파일이 있을 거예요.
서버에 연결할 때 다음과 같이 사용할 ID 파일을 지정합니다.
ssh -i ~/.ssh/client1-identity[이메일 보호됨]
그러나 ID 파일을 지정하지 않고 다음과 같이 사용하는 경우:
SSH[이메일 보호됨]
오류가 발생했습니다.
user123에 대한 인증 실패가 너무 많습니다.
ID 파일이 지정되지 않고 ssh가 ID 파일을 찾을 수 있으면 모든 파일을 시도하기 때문이라는 것을 이해합니다.
~/.ssh/config
또한 파일을 편집하고 다음과 같이 지정할 수 있다는 것도 알고 있습니다 .
호스트 example.com PreferredAuthentications 키보드 대화형, 비밀번호
해당 연결이 알려진 ID 파일을 시도하는 것을 방지하기 위해.
따라서 내 ID 파일을 디렉터리 외부로 이동할 수 있거나 ~/.ssh/
구성 파일에서 ID 파일 인증을 비활성화하려는 각 호스트를 지정할 수 있지만 기본적으로 SSH에 검색하지 않도록 지시할 수 있는 방법이 있습니까? 신원 파일? 아니면 검색할 항목을 지정하시겠습니까?
답변1
IdentitiesOnly=yes
이 옵션을 다음과 함께 사용할 수 있습니다 IdentityFile
(참조ssh_config 매뉴얼 페이지). 이렇게 하면 찾아야 할 파일을 지정할 수 있습니다.
이 예에서 ssh는오직ssh_config 파일에 제공된 ID + 명령줄에 나열된 4개의 ID를 살펴보세요(에이전트가 제공한 ID는 무시됩니다).
ssh -o IdentitiesOnly=yes \
-o IdentityFile=id1.key \
-o IdentityFile=id2.key \
-i id3.key \
-i id4.key \
[email protected]
양식 -i
과 -o IdentityFile=
상호교환이 가능합니다.
에서는 .ssh/config
다음과 같은 구성을 포함할 수 있습니다.
Host example
User user123
Hostname example.com
IdentityFile ~/.ssh/id_rsa_example
IdentityFile ~/.ssh/id_rsa_example2
IdentitiesOnly yes
답변2
user76528의 짧은 답변맞습니다. 하지만 방금 이 문제가 발생했고 약간의 설명이 유용할 것이라고 생각했습니다. "ssh가 내 ID 파일 구성 옵션을 무시하는 이유는 무엇입니까?"에 대해 궁금하신 경우 이 솔루션에 관심이 있으실 수도 있습니다.
첫째, ssh_config의 다른 모든 옵션과 달리 ssh는 IdentityFile
찾은 첫 번째 옵션을 사용하지 않습니다. 대신 이 IdentityFile
옵션은 사용된 ID 목록에 해당 파일을 추가합니다. 여러 옵션을 쌓을 수 IdentityFile
있으며 SSH 클라이언트는 서버가 하나를 수락하거나 연결을 거부할 때까지 모든 옵션을 시도합니다.
ssh_config
둘째, ssh-agent를 사용하는 경우 ssh는 ' IdentityFile
(또는 -i
) 옵션 에 키를 지정하지 않은 경우에도 자동으로 에이전트의 키를 사용하려고 시도합니다 . 이것이 오류가 발생할 수 있는 일반적인 이유입니다 Too many authentication failures for user
. 옵션 을 사용하면 IdentitiesOnly yes
이 동작이 비활성화됩니다.
IdentitiesOnly yes
여러 사용자로 여러 시스템에 SSH로 연결하는 경우 의 전역 섹션을 배치 ssh_config
하고 각각을 IdentityFile
적절한 Host 하위 섹션에 배치하는 것이 좋습니다 .
답변3
나는 일반적으로 다음과 같이 합니다.
$ ssh -o IdentitiesOnly=yes -F /dev/null -i ~/path/to/some_id_rsa [email protected]
옵션은 다음과 같습니다:
-o IdentitiesOnly=yes
- CLI를 통해 제공되는 키만 사용하고$HOME/.ssh
ssh-agent를 통해 제공되는 키는 사용하지 않도록 SSH에 지시합니다.-F /dev/null
- 사용을 비활성화합니다$HOME/.ssh/config
-i ~/path/to/some_id_rsa
- 연결에 명시적으로 사용하려는 키
예
$ ssh -v -o IdentitiesOnly=yes -F /dev/null -i ~/my_id_rsa [email protected]
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /dev/null
debug1: Connecting to someserver.mydom.com [10.128.12.124] port 22.
debug1: Connection established.
debug1: identity file /Users/sammingolelli/my_id_rsa type 1
debug1: identity file /Users/sammingolelli/my_id_rsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3
debug1: match: OpenSSH_5.3 pat OpenSSH_5*
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: RSA f5:60:30:71:8c:a3:da:a3:fe:b1:6d:0b:20:87:23:e1
debug1: Host 'someserver' is known and matches the RSA host key.
debug1: Found key in /Users/sammingolelli/.ssh/known_hosts:103
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /Users/sammingolelli/my_id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 535
debug1: read PEM private key done: type RSA
debug1: Authentication succeeded (publickey).
Authenticated to someserver.mydom.com ([10.128.12.124]:22).
debug1: channel 0: new [client-session]
debug1: Requesting [email protected]
debug1: Entering interactive session.
Last login: Tue Dec 8 19:03:24 2015 from 153.65.219.15
someserver$
위 출력에서는 CLI를 통해 개인 키만 ssh
식별했으며 my_id_rsa
이를 사용하여 someserver에 연결한다는 점에 유의하세요.
특히 다음 섹션은 다음과 같습니다.
debug1: identity file /Users/sammingolelli/my_id_rsa type 1
debug1: identity file /Users/sammingolelli/my_id_rsa-cert type -1
그리고:
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /Users/sammingolelli/my_id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 535
debug1: read PEM private key done: type RSA
debug1: Authentication succeeded (publickey).
답변4
IdentityFile을 사용하되 암호 재요청을 피하기 위해 ssh-agent를 계속 사용하십시오.
사용에 대한 허용된 솔루션은 IdentitiesOnly yes
ssh-agent를 결코 활용할 수 없다는 것을 의미하며, 결과적으로 키를 로드할 때 암호 문구를 묻는 메시지가 반복적으로 표시됩니다.
계속 사용 ssh-agent
하고 '너무 많은 인증 실패' 오류를 방지하려면 다음을 시도해 보세요.
키를 자동으로 로드하는 대화형 콘솔 시작 스크립트를 제거합니다
ssh-agent
.AddKeysToAgent yes
클라이언트의 SSH 구성에 추가하십시오 . 처음 연결할 때 암호를 묻는 메시지가 표시되지만 그 다음에는 에이전트에 키를 추가합니다.ssh-add -D
'너무 많은 인증' 오류가 발생할 때 사용하세요 . 이것은 단순히 ssh-agent 캐시를 '재설정'(삭제)합니다. 그런 다음 동일한 세션 내에서 다시 연결을 시도하십시오. 암호를 입력하라는 메시지가 표시되며, 수락하면 해당 암호가 에이전트에 추가됩니다. 에이전트에는 키가 하나만 있으므로 연결이 허용됩니다. 그런 다음 재요청을 피하기 위해 동일한 세션 중에 향후 연결을 위해 ssh-agent가 계속 존재합니다.Host ex example.com User joe HostName example.com PreferredAuthentications publickey,password IdentityFile /path/to/id_rsa AddKeysToAgent yes