Securely Connecting with SSH: A Beginner's Guide
SSH (Secure Shell) is a tool that allows you to securely access and control another computer or server 🌐. It’s like a remote control for computers, making it possible to manage files, run programs, and make changes from anywhere as if you were physically present.
What is SSH and How Does It Work?
SSH uses encryption to establish a secure connection between two systems. Here’s how it works:
Keys for Security:
.🔐 Private Key: Your unique key that you keep secret. Think of it as your digital fingerprint.
.🔒 Public Key: The server’s lock that matches your key. It ensures only you can access it.
When you use SSH, your private key verifies your identity, and the server’s public key confirms its authenticity.
Generating Keys with ssh-keygen
ssh-keygen
is a command-line tool to create and manage SSH keys.
Key Concepts:
Public Key: Shared to encrypt data.
Private Key: Kept secret to decrypt data.
ssh-keygen :
Follow the prompts to generate a new key pair. The keys are stored in the .ssh
directory on your system.
Private key - id_ed25519
Connecting Your Local System to an AWS Server
To connect to an AWS server securely, follow these steps:
Locate Your Key File:
Ensure your downloaded key file (
linux.pem
) is in your directory.Check permissions using:
ls -l linux.pem
Set Correct Permissions:
Modify the key file to be read-only:
chmod 400 linux.pem
Establish the SSH Connection:
Use the following command:
ssh -i "linux.pem" ubuntu@<your-aws-public-ip>.
compute.amazonaws.com
Type
yes
to accept the connection.you can connect successfully…..
Server-to-Server SSH Connection
If you need to connect one server to another:
Download Key File from AWS:
Use EC2 Instance Connect to access the server.
Copy the private key using:
cat linux.pem
Create Key File on the Target Server:
Create a new key file and paste the copied content:
vim linux.pem
Save and set permissions:
chmod 400 linux.pem
Connect to the Other Server:
ssh -i "linux.pem" ubuntu@<other-server-public-ip>.
compute.amazonaws.com
Downloading Files from a Server to Your Local System
To transfer files securely:
Prepare the Server:
Create a test file on the server:
mkdir test echo "Hello, World!" > test/hello.txt
then go to
cd .ssh ( this is directory manage ssh key”s )
vim id_ed25519.pub or cat id_ed25519.pub
copy data
then type vim authorized_keys
paste public key data and save exit
Download File Locally:
Use the
scp
command:scp -i "linux.pem" ubuntu@<server-ip>:/home/ubuntu/test/hello.txt ./
orsudo scp -i "linux.pem" ubuntu@<server-ip>:/home/ubuntu/test/hello.txt ./
The file will now be on your local system.
Why is SSH Important?
SSH provides:
✅ Security: Keeps your data safe from interception.
🌐 Convenience: Manage remote systems from anywhere.
💡 Versatility: Transfer files, execute commands, and debug.
Installing Nginx Using SSH (Example)
Here’s how to install Nginx on a remote server:
Connect to the Server:
Install Nginx:
sudo apt update
sudo apt install nginx -y
sudo systemctl start nginx
sudo systemctl enable nginx
Then go to Dashboard - select ip-id
Then go to public id
Access Nginx:
Open your browser and navigate to http://<your-public-ip>
.
for example http://52.**.**.*/ ( your public ip address)
Uninstall Nginx
Using systemctl:
sudo systemctl stop nginx
sudo apt purge nginx
Verify Installation:
apt list --installed | grep ngnix
Note : you can install any type of package
like Docker, Zip, Jenkins, Ansible
Conclusion :
SSH simplifies secure remote management of systems. With its robust encryption and flexibility, it’s a vital tool for administrators, developers, and tech enthusiasts. Start using SSH to manage your systems with ease! 🚀