To launch all the Laravel-related commands later, and to install/configure some software beforehand, we will need to connect to our server via SSH, with Terminal. Let's set it up.
This can be done by clicking on the Connect to your instance button from the success page
or optionally from the instances menu by selecting instance and pressing connect button on the top right corner
Optionally you can copy the public IP for later somewhere else.
Here are exact instructions on how to connect to your server using the key you generated and downloaded when creating an EC2 instance and it works perfectly fine.
The only problem with that is it's not very convenient to have such a long command to remember or paste every time, and in addition, you need to be in a directory where the key file lies. So let's tweak this a bit.
These steps are optional
.ssh
folder in your home directory if it doesn't exist, this is where usually SSH keys are storeduser@local$ mkdir -p ~/.ssh
.ssh
directoryuser@local$ mv Downloads/ec2-demo-web-ubuntu-server.pem ~/.ssh
user@local$ chmod 400 ~/.ssh/ec2-demo-web-ubuntu-server.pem
18.195.117.231 ubuntu-aws
line to the /etc/hosts
file:root@local# echo "18.195.117.231 ubuntu-aws" >> /etc/hosts
Now you can substitute the IP address with ubuntu-aws
in your shell commands and it resolves into 18.195.117.231
.
By default server drops all ICMP requests, which means if you ping it won't respond
user@local$ ping ubuntu-awsPING ubuntu-aws (18.195.117.231) 56(84) bytes of data.^C--- ubuntu-aws ping statistics ---3 packets transmitted, 0 received, 100% packet loss, time 2072ms
You can check if SSH is accessible instead
user@local$ nmap -p 22 ubuntu-awsStarting Nmap 7.93 ( https://nmap.org ) at 2022-11-01 01:23 EETNmap scan report for ubuntu-aws (18.195.117.231)Host is up (0.033s latency). PORT STATE SERVICE22/tcp open ssh Nmap done: 1 IP address (1 host up) scanned in 0.09 seconds
The host is reachable, great!
user@local$ ssh -i ~/.ssh/ec2-demo-web-ubuntu-server.pem ubuntu@ubuntu-aws
And also you can have an alias by entering alias connect-ubuntu-aws="ssh -i ~/.ssh/ec2-demo-web-ubuntu-server.pem ubuntu@ubuntu-aws"
so you can connect to your server only by typing:
user@local$ connect-ubuntu-aws
For this alias to persist add the alias connect-ubuntu-aws="ssh -i ~/.ssh/ec2-demo-web-ubuntu-server.pem ubuntu@ubuntu-aws"
command to your ~/.bashrc
or ~/.zshrc
file, depending what shell you do use.
After a successful connection your terminal window might look similar to this:
user@local$ connect-ubuntu-awsWelcome to Ubuntu 22.04.1 LTS (GNU/Linux 5.15.0-1019-aws x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage System information as of Tue Nov 1 01:23:59 UTC 2022 System load: 0.0 Processes: 99 Usage of /: 25.5% of 7.57GB Users logged in: 0 Memory usage: 24% IPv4 address for eth0: 172.31.44.101 Swap usage: 0% * Ubuntu Pro delivers the most comprehensive open-source security and compliance features. https://ubuntu.com/aws/pro 79 updates can be applied immediately.45 of these updates are standard security updates.To see these additional updates run: apt list --upgradable Last login: Tue Nov 1 01:23:59 2022 from xx.xx.xxx.xxxTo run a command as administrator (user "root"), use "sudo <command>".See "man sudo_root" for details. ubuntu@ip-172-31-44-101:~$
Don't get confused by a different IP address on the ubuntu@ip-172-31-44-101:~$
prompt, this is the server's local IP and not the public one you used to connect.