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.
- Navigate to the > Connect to instance page.
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
- The page should look like this:
Optionally you can copy the public IP for later somewhere else.
- To connect to your instance from the terminal, we need to choose the SSH Client tab:
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
- Create a
.sshfolder in your home directory if it doesn't exist, this is where usually SSH keys are stored
user@local$ mkdir -p ~/.ssh
- Move the downloaded key to the
user@local$ mv Downloads/ec2-demo-web-ubuntu-server.pem ~/.ssh
- Modify permissions so only your user can read the key
user@local$ chmod 400 ~/.ssh/ec2-demo-web-ubuntu-server.pem
- You can have your own IP address to URL mapping by overriding returned DNS value or trying to remember the exact IP address. Let's append the
188.8.131.52 ubuntu-awsline to the
root@local# echo "184.108.40.206 ubuntu-aws" >> /etc/hosts
Now you can substitute the IP address with
ubuntu-aws in your shell commands and it resolves into
By default server drops all ICMP requests, which means if you ping it won't respond
user@local$ ping ubuntu-awsPING ubuntu-aws (220.127.116.11) 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.104.22.168)Host is up (0.033s latency).PORT STATE SERVICE22/tcp open sshNmap done: 1 IP address (1 host up) scanned in 0.09 seconds
The host is reachable, great!
- Connect to your server with this command from any folder in your shell:
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:
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
~/.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/advantageSystem information as of Tue Nov 1 01:23:59 UTC 2022System load: 0.0 Processes: 99Usage of /: 25.5% of 7.57GB Users logged in: 0Memory usage: 24% IPv4 address for eth0: 172.31.44.101Swap usage: 0%* Ubuntu Pro delivers the most comprehensive open-source security andcompliance features.https://ubuntu.com/aws/pro79 updates can be applied immediately.45 of these updates are standard security updates.To see these additional updates run: apt list --upgradableLast 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.
These steps are optional user@local$ mkdir -p ~/.ssh
how can one to open ssh client and run this command. can we run this command on our local computer through command prompt window terminal or we have to open AWS CloudShell on aws to run this command. Please guide us on this step. I'm stuck here.
user@local- shows that this is entered on your local machine, not remote server.