Establish bastion host

Harshal ThoratHarshal Thorat
2 min read

This article outlines command-line operations on Ubuntu, emphasizing user management, password setting, and shell environment checks. It highlights the critical role of the Secure Shell (SSH) protocol in securing open ports, like port 22 on EC2 instances, through public and private keys. The guide provides instructions for generating SSH keys, managing authorized keys, and establishing secure connections between servers to enhance security and communication over SSH.

here are some commands in used:


ubuntu@ip-172-31-5-169:~$ whoami
ubuntu
ubuntu@ip-172-31-5-169:~$ useradd -m babataji
useradd: Permission denied.
useradd: cannot lock /etc/passwd; try again later.
ubuntu@ip-172-31-5-169:~$ sudo useradd -m babitaji
ubuntu@ip-172-31-5-169:~$ ls
commands.txt  devops
ubuntu@ip-172-31-5-169:~$ cd /home
ubuntu@ip-172-31-5-169:/home$ ls
babitaji  ubuntu
ubuntu@ip-172-31-5-169:/home$ sudo useradd patil
ubuntu@ip-172-31-5-169:/home$ ls
babitaji  ubuntu
ubuntu@ip-172-31-5-169:/home$ sudo useradd -m patil
useradd: user 'patil' already exists
ubuntu@ip-172-31-5-169:/home$ sudo useradd -m bhide
ubuntu@ip-172-31-5-169:/home$ ls
babitaji  bhide  ubuntu
ubuntu@ip-172-31-5-169:/home$ sudo passwd babitaji
New password: 
Retype new password: 
Sorry, passwords do not match.
passwd: Authentication token manipulation error
passwd: password unchanged
ubuntu@ip-172-31-5-169:/home$ sudo passwd babitaji
New password: 
Retype new password: 
passwd: password updated successfully
ubuntu@ip-172-31-5-169:/home$ su babitaji
Password: 
$ whoami
babitaji
$ exit
ubuntu@ip-172-31-5-169:/home$ whoami
ubuntu
ubuntu@ip-172-31-5-169:/home$ $shell
ubuntu@ip-172-31-5-169:/home$ $SHELL
ubuntu@ip-172-31-5-169:/home$ echo $SHELL
/bin/bash
ubuntu@ip-172-31-5-169:/home$ man useradfd
No manual entry for useradfd
ubuntu@ip-172-31-5-169:/home$ man useradd
ubuntu@ip-172-31-5-169:/home$ sudo useradd -m tappu -s /bin/bash
ubuntu@ip-172-31-5-169:/home$ sudo passwd tappu
New password: 
Retype new password: 
passwd: password updated successfully
ubuntu@ip-172-31-5-169:/home$ su tappu 
Password: 
tappu@ip-172-31-5-169:/home$ echo $bash

tappu@ip-172-31-5-169:/home$ echo $shell

tappu@ip-172-31-5-169:/home$ echo $SHELL
/bin/bash
tappu@ip-172-31-5-169:/home$ ls

Why We Need SSH(Secure Shell) Protocol?

SSH protocol → accessible port 22 → NEED SECURITY FOR OPEN PORT AS OF I CREATE EC2 INSTANCES AND I WANT SECURITY

HERE IS AN CONCEPT CALLED PUBLIC KEY AND PRIVATE KEY

To check for public key and private key which is in my instance A name as my-server

cd Downloads
whoami
sudo useradd -m babitaji
 ssh -i my-server.pem ubuntu@ec2-0-0-0-0.ap-south-1.compute.amazonaws.com
ls
ls -a
cd .ssh
ls
pwd
ssh-keygen
//this will ensure you generated ssh key then  after

cat your_public_key
//what u do inside another instance
cd .ssh
ls

vim autherized_keys //to write and create inside mention public key here
cat autherized_keys //to check file content

// this for ensure wherther u establish connection with port 80 i.e server A to server B
cd
ls
touch newfile.txt
ls
echo "this is server B" >newfile.txt
cat newfile.txt

//after ssh-keygen command 
ls  //check available keys
cat private_key
cat public_key
vim autherized_keys
cat public_key
ssh -i private_key utuntu@ip
//it will soon establish connection
//you can read write check 
exit
0
Subscribe to my newsletter

Read articles from Harshal Thorat directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Harshal Thorat
Harshal Thorat

Software Developer successfully implemented DevOps principles