Amazon EC2 인스턴스에 대한 SSH 액세스를 설정하려면 어떻게해야합니까?
Ubuntu 10.4를 실행하는 Amazon EC2 인스턴스에 대한 SSH 액세스가 필요합니다. 내가 가진 것은 Amazon 사용자 이름과 암호뿐입니다. 어떤 아이디어?
기본적으로 SSH를 통해 EC2에 로그인하려면 프라이빗 키 파일이 필요합니다. 다음 단계에 따라 생성하십시오.
- https://console.aws.amazon.com/ec2/home으로 이동하고 기존 Amazon 계정에 로그인합니다.
- LHS 또는 https://console.aws.amazon.com/ec2/home?region=us-east-1#s=KeyPairs 에서 "키 페어"를 클릭합니다 .
- 사용자가 (또는 EC2 생성 프로세스 중에) 생성 한 KEY 목록이 표시되어야합니다.
- 아무것도 보이지 않거나 개인 키를 잃어버린 경우 "키 쌍 만들기"를 클릭하십시오.
- 고유 한 이름을 입력하고 Enter 키를 누르십시오.
- 개인 키를 저장하고 저장할 수있는 다운로드 패널이 나타납니다.
- 파일 권한 "0600"으로 어딘가에 보관하십시오.
- LHS 또는 https://console.aws.amazon.com/ec2/home?region=us-east-1#s=Instances 에서 "인스턴스"를 클릭합니다.
- ec2-instances 목록이 표시되어야합니다. 아무것도 표시되지 않으면 새로 만드십시오.
- EC2 머신을 클릭하고 퍼블릭 DNS 주소를 기록해 둡니다.
- 터미널 (Linux)을 열고 다음 명령을 입력하십시오.
ssh -i /path/to/private-key root@<ec2-public-dns-address>
-루트 사용자 이름은 배포 선택ec2-user
또는ubuntu
사용자 이름 에 따라 최신 릴리스에서 사용하지 않았습니다 .- Enter를 누르십시오
- 그게 다야.
ssh -i /path/to/private-key ubuntu@<ec2-public-dns-address>
ubuntu
대신 사용하십시오 root
. 문제가 해결 될 것입니다. 건배!
1 단계) ec2 컴퓨터에 할당 된 개인 키를 다운로드합니다 (생성시 한 번만 다운로드하므로 어딘가에 커밋하는 것이 좋습니다).
2 단계) 다음 명령을 실행합니다.
chmod 400 MyKeyPair.pem
ssh -i MyKeyPair.pem ec2-user@ec2-198-51-100-1.compute-1.amazonaws.com
공식 문서 : SSH를 사용하여 Linux / Unix 인스턴스에 연결
13.04의 현재 사용자는 "ubuntu"ssh -i ./mykey.pem ubuntu@ec2-xxx-xxx-xxx-1.compute-1.amazonaws.com입니다.
먼저 키 페어를 생성해야합니다. EC2 콘솔을 사용하여 생성하십시오. 그런 다음 개인 키를 ec2-user
사용하여 선택한 SSH 클라이언트를 사용하여 서버 (사용자 이름은 )에 SSH로 연결합니다.
일단 sudo su -
로그인하면 원하는 경우 루트를 얻기 위해 a 를 발행 할 수 있습니다 (참고 : 루트로 직접 로그인 할 수 없음).
MacOS를 사용하는 경우 SSH 구성 파일 (~ / .ssh / config)을 생성 / 편집하고 다음과 같이 입력해야합니다.
Host *.amazonaws.com
User ubuntu
Port 22
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null
IdentityFile ~/PATH/YOUR_DOWNLOADED_KEY.pem
그런 다음 EC2 인스턴스에 연결하려면 :
ssh MYNAME.amazonaws.com
더 이상은 없습니다!
AWS에서 Ubuntu를 설정하려면 다음 단계를 따르십시오.
- Amazon Web Services 에 로그인 하고 EC2를 선택 합니다.
- 선택 실행 인스턴스를 하고, 오른쪽 이미지 (우분투), 인스턴스 유형을 선택 VPC 네트워크와 서브넷, 스토리지를 구성하고있는 SSH 액세스를 허용하여 마법사에 따라 보안 그룹을 . 그럼 시작합니다 .
- 처음으로 키 페어를 설정하고 인스턴스에 할당해야 할 수 있습니다. 키 쌍에서 키 쌍을 생성 할 수도 있습니다 . 생성 된 PEM 파일을 다운로드하여 안전한 장소에 보관하십시오.
- 인스턴스가 시작되면 인스턴스가 초기화 되고 실행될 때까지 기다립니다 .
SSH를 통해 인스턴스에 액세스하려면 다음을 실행하세요.
PEM 파일을 지정하여 Linux 상자에 연결합니다.
ssh -i "file.pem" ubuntu@x.x.x.x
Make sure your PEM file has 600 permission (
chmod 600 file.pem
).
Troubleshooting
If you're running VPC instance, and your security group is correct (with the right rules) and it still doesn't work, in VPC section check your subnet which should be attached to your VPC (both used by your instance) and setup new rule in Route Table that has 0.0.0.0/0
as Destination and your Internet Gateway as Target.
For more details check: Troubleshooting Connecting to Your Instance
See also: Possible reasons for timeout when trying to access EC2 instance
1) First chmod
the .pem file
for restricting the file permissons as below
chmod 400 my-key-pair.pem
2)Then ssh
with the following commands directly from .ssh
folder
ssh -i my-key-pair.pem ec2-user@ec2-198-99-90-3.compute-1.amazonaws.com
Note:- To navigate into .ssh
folder. First press Ctrl + H
to display all the hidden files and finallycd .ssh
Not logging in as the correct user for you OS Distro could be the issue. For certain new AMI, the username may not be "ubuntu", but "ec2-user". For Amazon Linux, for instance I believe the user is "ec2-user". Eric Hammond gives examples here: http://alestic.com/2014/01/ec2-ssh-username
My suggestion, try:
ssh -i /path/to/file.pem ec2-user@ec2...
ssh -i /path/to/file.pem ubuntu@ec2...
ssh -i /path/to/file.pem root@ec2...
If you have the wrong AMI, you might just want to restart the machine altogether so you have uniformity amongst your clusters. If this is your problem, you'll probably want the same OS Distro's at least for your linux boxes.
Doing what is suggested in all these answers is not enough. Against each instance you see a security group. When you launch a new instance, you will have this thing set to default. You need to edit the security group and add the ssh port it. Later you need to add the 8080, 8443, 80, 443 ports also when you want to host your website.
I Accepted AWS offer to use the default security groups which included 'All Trafic' ports.
And, after many and many times trying to connect on my new ec2 instance, I just realized that I should edit my used security group and manually add to inbound and outbound the 22 port ( ssh ) !
Hope it helps !
First change permission of pem file by
chmod 400 path/to/key_pair.pem
Inside the file ~/.ssh/config add the following lines, at the top of the file
Host AWS
Hostname myserver.com
User myuser
IdentityFile path/to/.pem/file
port 22
Hostname take IP or link of server, User take username of server and Identity file is file downloaded from AWS when you created instance. Just Run the following command in terminal
ssh AWS
and enjoy it!
Note: To navigate into .ssh
folder. First press Ctrl + H
in home folder to display all the hidden files and finally cd .ssh
Make sure these thing in check
private key must have 400 permission
Make sure port 22 is open for AWS instance you are trying to access.
ssh -i privatekey.pem ubuntu@XXX.XXX.XXX.XXX
// XXX.XXX.XXX.XXX = your instance public ip
참고URL : https://stackoverflow.com/questions/6394762/how-do-i-set-up-ssh-access-for-an-amazon-ec2-instance
'developer tip' 카테고리의 다른 글
sizeof가 연산자로 간주되는 이유는 무엇입니까? (0) | 2020.09.18 |
---|---|
CHAR_BIT는 무엇입니까? (0) | 2020.09.18 |
익명 함수 속기 (0) | 2020.09.18 |
"이 작업을 수행하는 동안 오류가 발생했습니다." (0) | 2020.09.18 |
각도 2에서 다시로드하지 않고 경로 매개 변수 변경 (0) | 2020.09.18 |