<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Josh Klar</title>
    <description>The latest articles on Forem by Josh Klar (@klardotsh).</description>
    <link>https://forem.com/klardotsh</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1054949%2F2d83923f-37c5-4b49-8587-ae853ecf284b.png</url>
      <title>Forem: Josh Klar</title>
      <link>https://forem.com/klardotsh</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/klardotsh"/>
    <language>en</language>
    <item>
      <title>"I need to test something on a Mac real quick", as solved by AWS EC2</title>
      <dc:creator>Josh Klar</dc:creator>
      <pubDate>Thu, 14 Sep 2023 08:36:47 +0000</pubDate>
      <link>https://forem.com/klardotsh/i-need-to-test-something-on-a-mac-real-quick-as-solved-by-aws-ec2-3og9</link>
      <guid>https://forem.com/klardotsh/i-need-to-test-something-on-a-mac-real-quick-as-solved-by-aws-ec2-3og9</guid>
      <description>&lt;p&gt;Like &lt;a href="https://arstechnica.com/gadgets/2023/07/report-linux-desktops-hit-3-global-market-share-but-are-declining-in-us/" rel="noopener noreferrer"&gt;approximately 3% of the desktop user pool globally&lt;/a&gt;, I use Linux on my workstations. Most of the time, this is all I need, and all I've needed for about the past 15 years since I was introduced to Linux on the desktop. However, every so rare often in my platforms and developer tooling work, I need to test something on MacOS specifically (which the bulk of the team here at Forem uses for their development environments). Thankfully, it's reasonably straightforward to spin up temporary-ish Macs in the cloud with AWS's EC2, including with secure graphical access over VNC, so let's do a bit of a lightning round (or as close to one as we can get - this is still somewhat of an elaborate dance!) setting such a thing up. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Before we begin &lt;em&gt;anything&lt;/em&gt; here, it's important to note that unlike many EC2 instances, Mac instances have a &lt;em&gt;minimum&lt;/em&gt; time allocation of 24 hours. Consider this for billing purposes.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;First, let's define what we want:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;An ARM64 ("Apple Silicon") MacOS EC2 instance&lt;/li&gt;
&lt;li&gt;Secure access to both the CLI and GUI of said machine&lt;/li&gt;
&lt;li&gt;Quick setup involving as few tools on our own (presumably Linux) workstation, and as little AWS knowledge, as possible&lt;/li&gt;
&lt;li&gt;The ability to tear all of this down quickly when we're done with it&lt;/li&gt;
&lt;li&gt;To not break the bank doing all of the above&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These criteria restrict us in a few noteworthy ways:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://instances.vantage.sh/aws/ec2/mac2.metal" rel="noopener noreferrer"&gt;Due to ARM Mac Mini region support&lt;/a&gt;, our EC2 instance must live in &lt;code&gt;us-east-1&lt;/code&gt; (Virginia), &lt;code&gt;us-east-2&lt;/code&gt; (Ohio), &lt;code&gt;us-west-2&lt;/code&gt; (Oregon), &lt;code&gt;eu-west-1&lt;/code&gt; (Ireland), or &lt;code&gt;ap-southeast-1&lt;/code&gt; (Singapore). At time of writing, these regions vary slightly in pricing.&lt;/li&gt;
&lt;li&gt;Since MacOS's remote desktop support runs over VNC, &lt;a href="https://en.wikipedia.org/wiki/Virtual_Network_Computing#Security" rel="noopener noreferrer"&gt;a protocol not known for being particularly secure&lt;/a&gt;, we'll want to SSH tunnel it rather than forward a direct port (which would require more tinkering in AWS's firewalling console anyway, so this is a win-win).&lt;/li&gt;
&lt;li&gt;To avoid needing to set up tools and workflows locally to support it, we won't use Terraform or other Infrastructure As Code tooling to define the infrastructure here (to anyone who had bets out on whether I'd &lt;em&gt;ever&lt;/em&gt; encourage the use of the AWS console over an HCL file, here you have it! An exception case!.. though I may write a Terraform-friendly follow-up some day 😄). One fewer &lt;code&gt;tfstate&lt;/code&gt; to worry about is a nice bonus.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's dig in.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setup Notes
&lt;/h2&gt;

&lt;p&gt;First, we need to &lt;a href="https://signin.aws.amazon.com/" rel="noopener noreferrer"&gt;log into the AWS Console&lt;/a&gt;. If you're logging in as an IAM user, that user needs to have &lt;em&gt;quite&lt;/em&gt; broad permissions. &lt;a href="https://stackoverflow.com/a/75001343" rel="noopener noreferrer"&gt;Here's an example I haven't personally tested, but seems &lt;em&gt;pretty&lt;/em&gt; close, from memory&lt;/a&gt;. IAM security best practices are out of scope for this article; if you're doing everything as the account root user, that's between you and your password/API key management systems 🙂&lt;/p&gt;

&lt;p&gt;Next, let's head to &lt;a href="https://us-west-2.console.aws.amazon.com/ec2/home?region=us-west-2#Home:" rel="noopener noreferrer"&gt;the EC2 management interface in the region of choice&lt;/a&gt; (note the aforementioned region restrictions). In my case, I'll be using &lt;code&gt;us-west-2&lt;/code&gt; since I live in the Pacific Northwest anyway. Region selection always matters in AWS, but it will particularly matter here: we'll eventually be seeing the entire desktop of our instance, which is a considerable amount of graphical data being pushed over the wire, and perhaps more importantly, our mouse movements will be subject to whatever latency we have to the datacenter in question (on top of VNC protocol lag).&lt;/p&gt;

&lt;p&gt;From here, we're going to click the bright orange "Launch Instance" button. At time of writing, this is the only accent-colored button on the whole page, it can't be missed.&lt;/p&gt;

&lt;p&gt;Let's give our instance a name, perhaps, "Josh's MacOS Sandbox", and perhaps give it a tag (to make it easier to find later, or easier for whoever handles your billing audits to know that this charge is from a developer and not some application we host in this AWS account, if applicable). I'm adding &lt;code&gt;kind=dev&lt;/code&gt; as a tag.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frkiheu4t76kzmzado7es.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frkiheu4t76kzmzado7es.png" alt="Name and Tags subsection of EC2 Launch Wizard"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next up, we can use a Quick Start AMI rather than needing to browse through all of the AMIs to have ever roamed the earth - let's click the macOS Quick Start AMI. At the bottom left of this section of the page, there's a toggle for Architecture (this is below where it tells us the version of MacOS, which should always default to the newest version AWS supports). &lt;em&gt;This will default to &lt;code&gt;64-bit (Mac)&lt;/code&gt;, which is Intel!&lt;/em&gt; We need to change this dropdown to &lt;code&gt;64-bit (Mac-Arm)&lt;/code&gt; to get an M1 Mac!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxccnyps3w8f15vkiyqbu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxccnyps3w8f15vkiyqbu.png" alt="Application and OS Images (Amazon Machine Image) subsection of EC2 Launch Wizard"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can now skip the &lt;code&gt;Instance Type&lt;/code&gt; subheading: there's only one type of M1 Mac instance, and that's &lt;code&gt;mac2.metal&lt;/code&gt;, with 8 CPU cores and 16GB of RAM.&lt;/p&gt;

&lt;p&gt;Next up, we need to select a keypair that will be used to SSH into the box in question. If you already have one that you use for other EC2 boxen, it'll work here, too (SSH keys from Linux machines work fine on MacOS), or you can generate a new pair if needed.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkeoxnsxjrh52wvcugqkn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkeoxnsxjrh52wvcugqkn.png" alt="Key Pair (Login) subsection of EC2 Launch Wizard"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next up is the part many folks dread about EC2: the networking settings. Thankfully, the defaults are exactly what we want: default VPC, default subnet in any availability zone, automatic public IP addresses, a new (&lt;em&gt;not&lt;/em&gt; existing, unless you know what you're doing!) security group, and SSH traffic (and &lt;em&gt;only&lt;/em&gt; SSH traffic) allowed from anywhere (&lt;code&gt;0.0.0.0/0&lt;/code&gt;). Is this what we want for a production system? Of course not! Is this a production system? Of course not! Quick and dirty, get 'er done. If your company (or default VPC) forbids access from "anywhere", you'll need to reconcile this somehow: a common way to do so is with a "bastion host", which beyond mentioning the existence of such, is beyond the scope of this article and an exercise for the reader.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you're reasonably confident your external IP address rarely-if-ever changes, you could consider restricting traffic to "My IP" from the dropdown. This is a great option if you work from a corporate office with a single outbound connection (small businesses often quality), an okay option if you work from a home office on cable or fibre, and a horrible option if you use LTE, Starlink, or any other heavily-CGNAT-ed connection. If you don't know what "heavily-CGNAT-ed connection" means or don't know what the backbone of your outside-world connection is, stick to "Anywhere".&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9hgj7w9c93oe9yfguhdf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9hgj7w9c93oe9yfguhdf.png" alt="Network Settings subsection of EC2 Launch Wizard"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally, if needed, increase the disk size from the default 100GiB, but note that it's impossible to shrink below that (the AMI snapshot was created with a 100GiB disk).&lt;/p&gt;

&lt;p&gt;When we try to click the orange &lt;code&gt;Launch Instance&lt;/code&gt; button on the right sidebar (see image below), we'll get an error complaining that we need to choose a Dedicated Host to launch the instance onto, an implementation detail of the fact that EC2 Macs are bare-metal instances and not VMs like most Linux instances are. Select "Dedicated host - launch this instance on a dedicated Host" from the dropdown.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvnrjyyaae5rnnh1ge56a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvnrjyyaae5rnnh1ge56a.png" alt="Summary subsection of EC2 Launch Wizard"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3dxfhajgrf09zcpmt32b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3dxfhajgrf09zcpmt32b.png" alt="Tenancy selection within the advanced subsection of the EC2 Launch Wizard"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If we try launching the instance again at this point, we get this lovely error message (transcribed in the alt-text):&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0l4pa10yabyhvlow9fmf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0l4pa10yabyhvlow9fmf.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Don't close the tab here! Instead, let's right click the &lt;code&gt;EC2&lt;/code&gt; link found towards the top of the page and open it in a new tab to go take care of some Dedicated Host housekeeping to get a host to launch this instance on.&lt;/p&gt;

&lt;p&gt;In the sidebar, let's head over to "Dedicated Hosts".&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpxa2jmmpjo6xjst9ardw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpxa2jmmpjo6xjst9ardw.png" alt="A screenshot of the EC2 sidebar with "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On this page there's a single accent-colored button labeled "Allocate Dedicated Host". Let's do the thing. On the next screen, we can name the instance whatever we want (I'm going with "Josh's MacOS Sandbox" again since I intend to tear this Dedicated Host down fairly soon rather than to leave it for reuse by a coworker later, which is what this tutorial will assume, but season to taste as necessary), and &lt;em&gt;must&lt;/em&gt; select &lt;code&gt;mac2&lt;/code&gt; for the Instance Family. &lt;code&gt;mac2.metal&lt;/code&gt; should be the only option for Instance Type. Pick an Availability Zone at random (&lt;code&gt;Math.ceil(Math.random() * 4)&lt;/code&gt; if you don't believe in humans' ability to choose values at random, a philosophical debate for another time), and &lt;em&gt;enable Instance Auto-Placement&lt;/em&gt; (something I failed to do in the screenshot below...). &lt;em&gt;You must disable Host Maintenance as &lt;code&gt;mac2&lt;/code&gt; instances don't support it.&lt;/em&gt; Everything else is somewhat at your discretion, though it's helpful to add the same tags you added to the EC2 instance config to the Dedicated Host as well (in my case, &lt;code&gt;kind=dev&lt;/code&gt;). Review the screen and smash that Allocate button (there's thankfully no bell to ring).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6kiwagihrq5lf23qgqju.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6kiwagihrq5lf23qgqju.png" alt="Allocate Dedicated Host screen in EC2 Console"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With the host now allocated, we can close this tab and head back to the instance config tab and hit Retry Failed Tasks. At this point we should see a successful instance launch:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnch8c5rsv7rljty3x3w4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnch8c5rsv7rljty3x3w4.png" alt="Successfully initiated launch of instance"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next up, let's connect to the instance over SSH. AWS helpfully provides a shortcut button for this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fix1a1l2lf2mlpjtdbjri.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fix1a1l2lf2mlpjtdbjri.png" alt="Connect To Your Instance box"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On this screen we're given SSH connection instructions. You'll need to modify them to reflect wherever you store your SSH keys locally, but in general, they should Just Work to get a shell connection to our Mac, which will be the basis for getting our GUI set up. Note that you should probably give the box about 5 minutes to boot up after launching the instance. This is a great opportunity to stare off into the abyss and think about your life decisions, or grab a coffee, or whatever.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note! As a rule of thumb, never expect a MacOS terminal to have a clue how to handle Linux terminal emulators or their terminfo, even if you override the &lt;code&gt;TERM&lt;/code&gt; environment variable to something generic like &lt;code&gt;xterm-256color&lt;/code&gt;. Prepare for your Home and End keys to likely do nothing useful, as just one example.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fatr9kbkuaf4ptgwszc9t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fatr9kbkuaf4ptgwszc9t.png" alt="A screenshot of my terminal after having shelled into the EC2 instance for the first time"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;While the box comes with a few useful things such as &lt;a href="https://brew.sh" rel="noopener noreferrer"&gt;Homebrew&lt;/a&gt; out of the box, such exploration is mostly left as an exercise to the reader depending on what they actually want to accomplish with the instance. If you're only interested in CLI access to the box, you're done with setup and can head down to the Teardown Notes below. For the rest of us looking for GUI access, read on.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://repost.aws/knowledge-center/ec2-mac-instance-gui-access" rel="noopener noreferrer"&gt;As the AWS re:Post Knowledge Center describes&lt;/a&gt;, we'll need to run a few commands in the shell to get VNC access to the machine:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;defaults write /var/db/launchd.db/com.apple.launchd/overrides.plist com.apple.screensharing &lt;span class="nt"&gt;-dict&lt;/span&gt; Disabled &lt;span class="nt"&gt;-bool&lt;/span&gt; &lt;span class="nb"&gt;false
sudo &lt;/span&gt;launchctl load &lt;span class="nt"&gt;-w&lt;/span&gt; /System/Library/LaunchDaemons/com.apple.screensharing.plist

&lt;span class="c"&gt;# And now set a password for the user, since we otherwise connect only with keyfiles over SSH.&lt;/span&gt;
&lt;span class="nb"&gt;sudo&lt;/span&gt; /usr/bin/dscl &lt;span class="nb"&gt;.&lt;/span&gt; &lt;span class="nt"&gt;-passwd&lt;/span&gt; /Users/ec2-user
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, use &lt;code&gt;Ctrl-D&lt;/code&gt; or &lt;code&gt;exit&lt;/code&gt; to leave the shell we currently have open, and let's spin up a new SSH connection that adds port forwarding (&lt;code&gt;-L 5900:localhost:5900&lt;/code&gt;, which says "when I connect to port 5900 on my workstation, pass the data through the SSH tunnel onwards to whatever &lt;code&gt;localhost&lt;/code&gt; means on the remote server, port 5900). If we previously may have used &lt;code&gt;ssh -i ~/.ssh/aws-forem-klardotsh-1.pem ec2-user@ec2-000-000-000-000.us-west-2.compute.amazonaws.com&lt;/code&gt;, we'll now use &lt;code&gt;ssh -i ~/.ssh/aws-forem-klardotsh-1.pem -L 5900:localhost:5900 ec2-user@ec2-000-000-000-000.us-west-2.compute.amazonaws.com&lt;/code&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Importantly, you'll see no special output relating to that port forward here! You'll be dumped into a plain old normal shell, just like we had before. That's okay, just know that you must keep this shell open while VNCing into the box.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Next up, we need some sort of VNC client on our workstation. I strongly recommend &lt;a href="https://remmina.org/" rel="noopener noreferrer"&gt;Remmina&lt;/a&gt; if you value not spending your time debugging and configuring things. Just select "VNC" from the main connection bar's dropdown, punch in &lt;code&gt;localhost:5900&lt;/code&gt;, and hit enter. An authentication screen will pop up: fill it with &lt;code&gt;ec2-user&lt;/code&gt; for the username, and whatever password you provided to &lt;code&gt;dscl&lt;/code&gt; earlier.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhojsnjmszb8pqmy3rt7p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhojsnjmszb8pqmy3rt7p.png" alt="Remmina screenshot"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hit Ok, wait a moment, and - voila! We have graphical access to our Mac, albeit a locked one. We'll need to log in one more time, but at this point, we have full GUI access to a real M1 Mac! Develop away, but be sure to check out Teardown Notes below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgmow3bph5trthzeho40l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgmow3bph5trthzeho40l.png" alt="Screenshot of the About This Mac screen via the VNC connection"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you close the terminal hosting the SSH connection, the VNC connection will also die, so be sure to disconnect cleanly from VNC before closing that terminal.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Teardown Notes
&lt;/h2&gt;

&lt;p&gt;To tear down our stack when we're done, we'll need to keep a few things in mind, &lt;a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-mac-instances.html" rel="noopener noreferrer"&gt;which are documented in the AWS User Guide&lt;/a&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Destroying the EC2 instance will take &lt;em&gt;lots&lt;/em&gt; of time.&lt;/li&gt;
&lt;li&gt;Destroying the EC2 instance only destroys the running system, but does &lt;em&gt;not&lt;/em&gt; release our claim on the underlying Reserved Host. We will be billed for the reserved host in the meantime.&lt;/li&gt;
&lt;li&gt;Releasing the Dedicated Host can be done only a &lt;em&gt;minimum&lt;/em&gt; of 24 hours after we originally claimed it. Blame Apple's licensing here for the lack of quick turnaround.&lt;/li&gt;
&lt;li&gt;Optionally, remember to tear down the related security group that was automatically created by AWS during instance config creation.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Happy hacking!&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>aws</category>
      <category>macos</category>
      <category>devex</category>
    </item>
  </channel>
</rss>
