Have a Mac but need a Linux? Just do this…

Niole Nelson
Niole Net
Published in
4 min readFeb 13, 2021

--

Recently I was reading about systemd: a service manager for Linux operating systems. Why was I reading about this? Basically just curiosity about debugging Linux systems. Do you know how many times I’ve been faced with a malfunctioning machine and could not troubleshoot it for the life of me? SO many times. Way too many times. That’s not the point of this post, though…

So, I wanted to read through the systemd man page and try some stuff out. I go to my Mac OS command line and type in systemd thinking, “Unix, Linux, tomato, potato”. Lo and behold,

command not found: systemd
Unix is not just Linux with an “L” in front

Suddenly, a stroke of genius…

I’ll create an AWS account and launch a Linux machine there! I’ll just ssh in, install some dev-tooly stuff and do all the Linux development my little heart desires.

Launching A Free Linux Machine on AWS

First thing, launch a free EC2 instance. You want to pick the AMI (Amazon Machine Image) and is Linux and free tier eligible.

Probably this one

Pick defaults for All the Things, until you hit Security Groups. Pay attention, this is important.

Network Security Groups

why though? this is just for fun times development, nothing special

In order to use our machine, we will have to ssh into it. This means that our machine is accessible across the entire internet.

Now, I used to be one of those people who didn’t care about that kind of thing, UNTIL I deployed my own full stack application with a reverse proxy server that logs all connections made to it. Seeing the logs of 20 different random IPs spamming my server from all across Asia, looking for Bank of America login forms and Apache Tomcat admin dashboards scared the CRAP out of me.

Set the Source IP Rule to be Your Machine Only

When you reach the network security group section, configure one security group that only allows your home machine to send traffic to the EC2 instance.

Find out your IP address by running this command:

dig +short myip.opendns.com @resolver1.opendns.com

Configure a security group to only allow incoming connections from your machine by pasting in a source IP rule in CIDR notation: <your-ip>/32.

The /32 suffix is the network mask associated with the source rule. It indicates that the 32 leading bits of the associated IP address must be included in all inbound requests. 32 bits == 4 bytes, an IPv4 address is 4 bytes therefore <your-ip>/32 means that only addresses matching <your-ip> can send network traffic to this machine.

172.31.30.221/32

Create and Download an SSH Key Pair

Next, we will need to create a public-private key pair in order to ssh into the machine securely. Just follow the prompts and hit download. The prompt will probably look something like this,

Launch that instance!

SSHing into Your New Linux Machine

All right, the machine is running. Now we will connect to it over ssh. We need to get the machine’s public IP address so that we can connect to it. Go to the EC2 instances dashboard, find your machine in the table. The public IP address should be right there:

Public IPv4…

Next, we need to figure out that the default user is for the AMI that we chose. My AMI is “Amazon Linux”. The Amazon EC2 User Guide tells me that the default user for my AMI is ec2-user. Altogether now…

ssh -i ~/Downloads/my-linux-machine.pem ec2-user@52.11.247.26

You might get an error like this…

oh noes

Your .pem file is readable by too many users. Change the permissions on your .pem file so that it’s only readable/writable by your user: chmod 600 my-linux-machine.pem, and try sshing in again.

🔥🔥🔥 Hooray, You Made It In

Nice, you did it. Run some Linux commands and revel in the glory of your new Linux machine.

Some next steps could include making this environment more “dev friendly” by installing vim so that you can edit files, git so that you can save your work somewhere, and maybe a terminal multiplexer like tmux so that you can have multiple windows in your single ssh session. Usually you can install these things using a package manager that already exists on your machine. Use which to search for some common ones:

yum it is

Give this a try:

sudo yum install vim tmux git -y

Have fun!

--

--