Successfully Tackling a Roadblock // EC2, Adding a New User & the Final Push

Melissa (Mel) Foster
Women in Technology
6 min readMar 13, 2023

Expanding on my last project, I wanted to push myself further and create a Repository in GitHub to store my Bash Scripts. As well as create a new script to set up a user to my EC2. You can view my last project here: https://medium.com/@mel.foster/launching-an-aws-ec2-instance-creating-a-custom-webpage-75c5ebd3e1c5

To follow along with this portion you will need:

  • AWS (Amazon Web Service Account)
  • Running EC2
  • Access to PowerShell/Terminal
  • GitHub Account
  • Patience

To start, log into your GitHub account and let’s set up a new repository. You will see you as the owner, and you can customize your repository’s name, description, viewability/accessibility. You can choose to have a README File or not to have it. (It is recommended)

Once you get to the bottom of the fields you will see Create repository. Go ahead and click.
Your GitHub Account should now show your newly created repository.

Before you leave your GitHub page you can go ahead and set up a token that will act as your password in PowerShell/Terminal when you are ready for the final push back to your repo. If you haven’t set up a Token before follow these steps.

  • From your profile choose Settings
  • Scroll down to Developer Settings
  • Choose Personal access tokens
  • Choose Token Classic
  • Next choose Generate Token and choose Generate Classic Token
  • Select all the boxes and then at the bottom of the screen you will choose generate token one last time.
  • IMPORTANT- a screen will populate with your Token. It will only show ONE TIME. Copy and paste it to a location where you will not lose it or forget it!

With your token now saved we will switch over to our EC2 and continue onwards.

Our next steps will be ensuring your EC2 Instance is “Running” in your AWS account, and with our new repo set up we can ssh into our EC2 using our PowerShell/Terminal.

If we ls we will see that our apacheinstall.sh is still all by itself. Let’s put it in a directory and get ready to push it to our GitHub Repo.

mkdir Scripts

mv apacheinstall.sh /Scripts
apacheinstall.sh is now moved into our Script Directory

Before we continue we need to cd locations back to our home to install Git using the cd ~ command. In our home directory we can now install:

sudo yum install git
Success

With Git successfully installed we will take a scroll over to our GitHub Account and clone the repo we created together into our PowerShell/Terminal.

Back in PowerShell/Terminal use the git clone command along with your copied https address

git clone https://github.com/mel-foster/LUIT-Scripts.git
Success we can now see our Cloned Directory

Here, is where I hit a road block. Not sure why, but at this point my PowerShell was no longer allowing me to use the mv command. Every time I would try to mv my script into the new LUIT-Scripts Directory it would disappear. I ended up getting great practice writing the script over and over again. (Save yourself some time and copy your scripts somewhere for reference use later, where you can copy & paste) I even tried to use the command cp and the direct path and it still would just disappear into the matrix. Did I give up? Nope! I stopped my Instance, took a break, restarted my entire system, checked for updates, and went to bed.

With fresh eyes, and a rebooted system we are once again logging into AWS, to restart our EC2 Instance. As well logging back into PowerShell to attempt a few things.

Failure again with mv command. (Screen grab failed to save). Sort of feels like it’s just not meant to be at this point. I just can’t throw in the towel yet.

Let’s verify our files and directories one more time. As you can see in my successful screen grab, we have two directories. Using the cd command we can go into our first directory LUIT-Scripts (This is our cloned repo) and use pwd to get the correct direct path. My next step was to cd again back to home, then cd into Scripts, where my final executed working bash script for the Apache custom webpage is patiently waiting to be moved. (My script’s name might have changed but the functionality did not.)

Here we go last attempt, using cp to copy my script into LUIT-Scripts directory.

Success with sudo cp command utilizing a direct path

It MOVED!! YES!!! Air fist pumps!! We have successfully moved a copy of our successfully executed bash script to our LUIT-Scripts Directory!

We have one more script to finish writing. Our newuserscript.sh this will allow us to add a new user to our EC2.

Remember it is ok to utilize an example script, but give credit to original author. I researched example scripts and landed using one from https://www.cyberciti.biz/faq/unix-linux-bash-read-comma-separated-cvsfile/

Don’t forget to make your script executable

chmod +x newuserscript.sh
Now we have two scripts that are executable and we are almost ready to push to our GitHub

Before we push to our GitHub let’s test out our newuserscript.sh and add a test user.

New user has been added to the system!

Using the command cat /etc/passwd we can see our user has in fact been added.

To ensure our new user will now be able to access everything appropriately we need to edit the ssh_config file in the /etc directory. I chose to do this as the root user using the command sudo su.

As the root user we can now edit the ssh_config file by using vim.

vim /etc/ssh/sshd_config

Scroll down till you see PasswordAuthentication and change the no to yes

Remember to hit the Esc key to end our Insert Editing Capability and choose :wq to write and exit

We need to restart the sshd by

service sshd restart
Let’s exit and logout

Let’s log back in as our user:

Note: I thought I would create a new user as myself as well

We are in the final stretch of this advanced and complex follow-up to the foundations of launching an AWS EC2. Let’s push all our scripts to our GitHub.

Commands will be used for both scripts and ran separately.

git add
git status
git commit -m "your descriptive notation"
git push
enter github username
enter github password which will be the token we generated
Remember Spelling and Case Sensitivity are important; You can see I used get vs git one time.
Here you can see our Successful Push!!
Here is our Foundational Week 5 Bash Script we created now visible in our GitHub Repo
Here is our new user script

That’s a wrap! Thank you so much for following along! I hope are inspired to persevere through challenges and not give up. I am glad I didn’t!

--

--

Melissa (Mel) Foster
Women in Technology

𝔻𝕖𝕧𝕆𝕡𝕤 𝗘𝗻𝗴𝗶𝗻𝗲𝗲𝗿 |𝒲𝑜𝓂𝑒𝓃 𝐼𝓃 𝒯𝑒𝒸𝒽 𝒜𝒹𝓋𝑜𝒸𝒶𝓉𝑒 | 𝚂𝚘𝚌𝚒𝚊𝚕 𝙼𝚎𝚍𝚒𝚊 𝙲𝚛𝚎𝚊𝚝𝚘𝚛 | Photographer