Log In to an Instance

To log in to an instance with a Secure Shell connection, you must know the instance’s public DNS name or IP address; and the instance must be running in a security group that is configured to allow inbound network access to the Secure Shell daemon service on port 22. If the instance is configured to use keypair access credentials, you must also have the private key file corresponding to the keypair associated with the instance.

We will log in to our instance, which is located at the public DNS address ec2-67-202-4-222.z-1.compute-1.amazonaws.com, as the root user. At a console prompt, we will run the ssh Secure Shell command and provide our private key file as an identity file. Because we have encrypted our private key file, we will be prompted for a password when we try and use it.

$ ssh -i ec2-private-key.enc root@ec2-67-202-4-222.z-1.compute-1.amazonaws.com

You will most likely have to explicitly allow ssh to connect to this particular host for the first time by answering “yes” to the question about continuing the connection.

The authenticity of host 'ec2-67-202-4-222.z-1.compute-1.amazonaws.com 
(67.202.4.222)' can't be established.
RSA key fingerprint is f9:9c:3b:f2:f0:75:74:a9:10:5a:8a:18:74:48:63:55.
Are you sure you want to continue connecting (yes/no)? yes

Note

If this is the first time you have used your private key file, the ssh program may complain that this file has overly lax file permissions. If this happens you must set the appropriate permissions ...

Get Programming Amazon Web Services now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.