Amazon EC2 권한 거부 됨 (공개 키)
이것은 일반적인 문제인 것 같지만 내 특정 사례는 약간 다릅니다.
명령 줄 도구를 사용하여 새 Amazon EC2 인스턴스를 설정하고 SSH를 통해 연결하고 몇 가지 구성 작업을 수행했습니다.
하지만 처음에는 인스턴스에 ssh 할 수 없었고 인스턴스를 중지했다가 다시 시작한 다음 연결할 수있었습니다. 다시 시작하기 전에 방금 응답을 받았습니다.
Permission denied (publickey).
그게 어제 밤이었는데, 오늘 아침에 같은 인스턴스로 돌아가서 지금 얻는 건
Permission denied (publickey).
기쁨없이 인스턴스 재부팅을 시도했습니다.
누구든지 여기에서 올바른 방향으로 나를 가리킬 수 있습니까? 어제 밤에 작동했던 동일한 명령이 더 이상 작동하지 않으며 Macbook Pro에서 연결하고 있습니다.
다른 사람이 같은 것을 볼 경우를 대비하여 내 질문에 답할 것입니다. 지난 밤에 내가 한 일 :
ssh-add ~/.ssh/[keypair name]
다음과 연결되었습니다.
ssh ec2-user@[ec2 instance ip]
오늘 아침 나는 똑같이 시도했지만 연결할 수 없었습니다. 하지만
ssh -i ~/.ssh/[keypair name] ec2-user@[ec2 instance ip]
날 들어간다.
ssh-add키 쌍을 사용하면 다시 들어 오게됩니다. 내가 ssh-add발행 한 셸 내에서만 작동하는 것 같습니다. 터미널 창을 닫고 다른 창을 열었을 때 더 이상 명시 적이 지 않은 키 쌍을 사용할 수 없었습니다.
올바른 사용자 이름을 사용하지 않았기 때문에 이런 일이 발생했습니다. 튜토리얼에 사용 된 AMI를 사용하여 로그인 할 수 있었는데 다른 AMI (Bitnami의 ubuntu + LAMP)를 사용하려고하면 Permission denied (public key).오류가 발생했습니다. 나는 마침내 내가에서 튜토리얼 아미의 이름을 변경 한 경우 실현 ubuntu에 ec2-user내가 같은 오류를 얻을 것입니다.
따라서 빠른 Google은 Bitnami AMI의 사용자 이름이 bitnami. 문제 해결됨.
비슷한 문제가 발생하여 홈 폴더에 대한 권한으로 밝혀졌습니다. 고맙게도 다른 기존 ssh 연결이 열려 있으므로 ec2 인스턴스의 로그를 확인할 수있었습니다.
$ sudo less / var / log / secure
포함 된 내용 :
Dec 9 05:58:20 ... sshd[29816]: Authentication refused:
bad ownership or modes for directory /home/ec2-user
이 문제는 다음 명령을 실행하여 수정되었습니다.
$ chmod og-rwx / home / ec2-user
다른 사람에게 도움이되기를 바랍니다.
인스턴스를 다시 시작한 후 DNS 이름이 변경되었습니다. 나는 이것을 여러 번 떨어졌다. 키 파일은 여전히 유효했지만 "servername"이 변경되었습니다.
감사합니다!
@Trevor의 답변에 정말 감사드립니다. 앞으로이 문제를 피하기 위해 지금 사용하는이 작은 트릭을 추가 할 것입니다.
편의
각 가용 영역에 대해 서로 다른 키 쌍을 만들어야하므로 키 쌍을 모두 관리하고이를 사용하는 명령을 관리하는 것이 상당히 번거 롭습니다. ~/.ssh/config내 ssh 명령 의 적절한 설정 은 다음과 같이 간단합니다.
ssh ec2-52-10-20-30.us-west-2.compute.amazonaws.com
이것이 US West 2 가용성 영역에있는 서버의 전체 공용 DNS입니다. 다음과 같은 이유로 적절한 사용자 이름과 키가 선택되었습니다.
## ~/.ssh/config
Host *.us-west-2.compute.amazonaws.com
User ec2-user
IdentityFile ~/.ssh/bruno-bronosky-aws-us-west-2.pem
EC2 인스턴스가 Ubuntu ami 14.04. EC2 인스턴스 IP 앞에 'ubuntu @'를 추가해보십시오.
ssh -i [key name] ubuntu@[EC2 instance ip]
개인 키 경로가 올바른지 확인하십시오.
ssh 클라이언트가 제공하려는 개인 키를 찾을 수 없으면 이상하게도 오류가 발생하지 않습니다! 그 키를 사용하지 않습니다. .ssh / id_dsa 및 .ssh / id_ecdsa 아래에있는 키를 사용합니다. 물론 공개 키 인증이 희미 해집니다.
~ / .ssh / id_rsa.pub의 내용을 EC2 인스턴스의 ~ / .ssh / authorized_keys에 복사하여이 문제를 해결했습니다.
이는 문서에 지정되어 있습니다. http://docs.aws.amazon.com/opsworks/latest/userguide/security-ssh-access.html
그런 다음이 명령을 사용하여 ssh 할 수 있습니다.
ssh ec2-user@[ip.address]
나는 또한 받았다 : 권한이 거부되었습니다.
나는 사용했다 :
ssh -v -i ~/.ssh/pemfile ec2-user@xx.xx.xx.xx
응답은 다음과 같습니다.
debug1: No more authentication methods to try.
다음 명령을 입력하십시오.
ssh-add -l
그러나 응답은 비어있었습니다
그래서 펜 파일의 형식에 문제가 있다고 생각합니다. 다음으로 ec2 웹에서 다운로드 한 펜 파일을 찾아서 옮겼습니다. 그 전에 새 파일을 만들고 다운로드 한 pem 파일의 텍스트를 ".ssh"디렉토리로 구문 분석 한 다음 :
ssh-add filename
성공적이었습니다.
I spent the whole day searching internet for the answer. My issue exact the same. I fiddled with permission issue, changed back and forth, yet none solved my problem. After test with a new key and start/terminate a couple instances, finally I found it has to do with the same key name in different regions.
This is how "Permission denied (publickey)" happened to me:
1. Follow the practice book, select the us-east-1 as default zone
2. Create a key name "mykey"
3. Exploring AWS world by following examples in that book.
4. One day, try to test speeds of Sydney zone, switch to Sydney Zone as default on.
5. Create another key, named it as "mykey" without thinking, but not use it to connect through cli for a couple days.
6. Try to connect to AWS using cli.
7. Got "Permission denied (publickey)".
8. Spent many hours to debug ssh issue until I notice the key/zone issue.
Hope this could help newbie like me.
To avoid this issue, I think the best practice to name a key is to attach a region in it.
I changed the permissions to 600, although the permissions on the pem file were 644 already. And that worked :p hope it helps
Had the same problem, here is what you should do. First of all, if you have Windows, use the Babun command line, which is like the Linux one. Once you have that command line, open it and type ssh-i [key pair path] [username]@[EC2 public IP]. To find the path for the key pair, go to the file where your key is stored, hold shift and right-click and click copy path, and paste it in where the path goes in the command above. You probably will get "" marks on the outsides of the path you pasted, and \ backslashes. Delete the "" marks and replace the \ backslashes with regular slashes /. This worked in a situation like this that I had, best of luck to you.
Connecting to EC2 from cli is a little bit tricky at least for the first time. If you go to `
Services -> Compute -> EC2 -> Running Instances > and select the instance you want to ssh -> connect
` then you will see the dialog box describing how to connect to it. Part of it is shown below.
If you use number 4 without preceding it with ec2-user@ you will get
Permission denied (publickey).
Just copy and paste the one mentioned below in the `Example:.
In my case the reason for this was I had changed the permissions of the root directory folder with chmod. In AWS web site they describe a long way to change the permissions back with another temporary instance. However, I just terminated the old instance and launched another one and this time did not make any change to the permissions of the root directory and all is ok.
참고URL : https://stackoverflow.com/questions/4826706/amazon-ec2-permission-denied-publickey
'Program Club' 카테고리의 다른 글
| 특정 노드를 방문하는 그래프에서 최단 경로 찾기 (0) | 2020.10.26 |
|---|---|
| 상승 된 권한이 있거나없는 관리자로 실행 중인지 감지 하시겠습니까? (0) | 2020.10.26 |
| 원시 값에 대한 PHP 유형 힌트? (0) | 2020.10.26 |
| Haskell의`head`가 빈 목록에서 충돌하는 이유는 무엇입니까 (또는 왜 빈 목록을 반환하지 * 않습니까 *)? (0) | 2020.10.26 |
| 이전 git 커밋 제거 (0) | 2020.10.26 |
