Connect to an Amazon EC2 Mac instance
Learn how to remotely connect to an EC2 Mac instance
About | |
---|---|
✅ AWS experience | Beginner - 100 |
⏱ Time to complete | 20 minutes |
💰 Cost to complete | $22 for 24 hours |
🧩 Prerequisites | An AWS Account |
💻 Code Sample | - none - |
📢 Feedback | Any feedback, issues, or just a 👍 / 👎 ? |
⏰ Last Updated | 2023-06-28 |
Note that there are some cases where the instance is already configured at start (this article shows you how to configure an instance ready to use). In those cases, there is no need to remotely connect to your instance. It is perfectly possible to start and use a pre-configured EC2 Mac instance without ever connecting to it. But for this tutorial, we assume you started the EC2 Mac instance from one of the AWS-provided Amazon Machine Image (AMI) and you have a clean macOS installation available.
- at launch time, you have specified the SSH keypair that will be used for user authentication. Note that this can only be done at launch time. If you forgot to do it launch, you may terminate your instance and start a new one, on the same dedicated host (it might take a while to scrub the machine when you terminate it, and before it becomes available again).
- the instance has been launched on a network (VPC) that has public network connectivity (a public subnet of the VPC), and your instance has a public IP address. These two parameters are the default values when launching an EC2 instance.
- at launch time, or afterwards, you have associated a Security Group with your EC2 Mac instance. The security Group is configured to authorize inbound TCP 22 (SSH) traffic from your laptop IP address or your client network IP range.
ec2-user
and you have to use the -i
option to refer to your private key, stored on your laptop.mac1.metal
instance running) - your IP address will be different than 1.0.0.0
used below:pem
file with the -i
option and use the default username AWS created for you on macOS: ec2-user
. In this example, we connect to a Big Sur instance (please remember to replace 1.0.0.0
with your instance's IP address from the previous command).
ec2-user
is included in the /etc/sudoers
file and you can elevate privileges to root with the sudo
command, without a password.arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore
.


exit
.ssm-user
(and not ec2-user
as with SSH). Both users are included in the /etc/sudoers
file and you can elevate privileges to root with the sudo
command, without using a password.ssh
to use aws ssm start-session
command as proxy command when SSH'ing to your hosts. If you're interested, or just curious, check out this documentation. ec2-user
, then start the Apple Remote Desktop server component.localhost:5900
).
-i
, allows you to specify the private part of the keypair used for authentication-L
is the SSH tunneling option. It tells the SSH client on your machine to start to listen to incoming connections on TCP port 5900 (5900:
), and to forward all traffic received to the destination host (1.0.0.0
). Once on the destination host, to send the traffic tolocalhost:5900
which is the address of the ARD server.-C
tells SSH to compress the traffic in the tunnel-N
tells SSH to not start an interactive session on the client. The command blocks until you interrupt it withCtrl-C
localhost
. The SSH tunnel will act as a server and forward all the traffic to the actual ARD server running on your EC2 Mac instance on the other side of the tunnel.Note that the URI starts withvnc://
because Apple Remote Desktop client is based on Virtual Network Computing (VNC) protocol.
ec2-user
) and the password you choose when you enabled ARD.


displayplacer
, the open source command line tool developed by Jake Hilborn.aws ssm
command with Ctrl-C
.Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.