Everything About SSH 🔒🗝️
What is SSH & Why We Use ?
SSH or Secure Shell is a network communication protocol that enables two computers to communicate (ex: http or hypertext transfer protocol, which is the protocol used to transfer hypertext such as web pages) and share data.
SSH Port Number : 22
How to Install SSH in Windows
Step 1: Open PowerShell With Run as Administration
Step 2: Copy this Command and Paste it
# Install the OpenSSH Client
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0
Step 3 : Copy this Command and Paste it
# Install the OpenSSH Server
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
Step 4:
Step 5: Restart Your PC/Computer
Step 6: Open CMD
// Make sure you are in same directory
C:\Users\yourprofile>
Type these Commands
// If there is no .ssh folder create it by (mkdir .ssh)
cd .ssh
// Generating New SSH Keys for Windows
ssh-keygen -t ed25519 -C "youremail@gmail.com"
// Press Enter 3 Times
// Check the files in .ssh
dir
// You have 2 keys
- id_ed25519 is your private key (Never Share it with Anyone)
- id_ed25519.pub (You can Share if you want to give access to others)
For Sharing File Access Always Share .pub key file
type id_ed25519.pub
// Copy It And Save it Somewhere
We will be need that key while sharing the access
Step 7: Open PowerShell with Administration
# Start the sshd service
Start-Service sshd
# OPTIONAL but recommended:
Set-Service -Name sshd -StartupType ‘Automatic’
# Confirm the Firewall rule is configured. It should be created automatically by setup. Run the following to verify
if (!(Get-NetFirewallRule -Name “OpenSSH-Server-In-TCP” -ErrorAction SilentlyContinue | Select-Object Name, Enabled)) { Write-Output “Firewall Rule ‘OpenSSH-Server-In-TCP’ does not exist, creating it…” New-NetFirewallRule -Name ‘OpenSSH-Server-In-TCP’ -DisplayName ‘OpenSSH Server (sshd)’ -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22 } else { Write-Output “Firewall rule ‘OpenSSH-Server-In-TCP’ has been created and exists.” }
How to Install SSH in Ubuntu/Linux
The procedure to install a ssh server in Ubuntu Linux is as follows:
- Open the terminal application for Ubuntu desktop.
- For remote Ubuntu server you can use Ubuntu Terminal
- Type this Command
sudo apt update && sudo apt upgrade
4. Type command:# sudo apt-get install openssh-server
5. Enable the ssh service by typing:# sudo systemctl enable ssh
6. Start the ssh service by typing:# sudo systemctl start ssh
7. Configure firewall and open port 22
You must configure the Ubuntu Linux firewall called ufw. Here is how open or allow port 22 when using ufw on Ubuntu:$ sudo ufw allow ssh
$ sudo ufw enable
$ sudo ufw status
8. Type this command
ssh-keygen -t ed25519 -C "youremail@gmail.com"
9. Press enter 3 times untill you get this
10.Setting up Permission on SSH Folder and Keys
Type this command’s Line By Line
sudo chmod 700 .ssh
cd .ssh
sudo chmod 644 id_ed25519.pub
sudo chmod 600 id_ed25519
11. Setting Up SSH Access
- Friend 1 (A)
- Friend 2 (B)
If Friend 1 wants to Access Friend 2 System Files
Then Friend 1 Should Share his Public keys with Friend 2
How it Looks
- Friend 1 Will Go to His .ssh folder
- Friend 1 Wil Copy the public key (id_ed25519.pub)
- Friend 1 will share the public key to Friend 2
- Now Friend 2 Will Open his .ssh folder
- create a file name authorized_keys
To Create a File in Linux
touch authorized_keys
6. To Open the file
nano authorized_keys
7. Paste the Friend 1 Public Key in authorized_keysfile
8. Ctrl + O To Save the File
9. Ctrl + X To Exit it
10. Make Sure Both Friend 1 and Friend 2 are in Connected to Same Wifi Network
11. Now Friend 1 wants to Access Friend 2 File System
12. Friend 2 Should share his private ip and username of it
13. Friend 1 Should Open his Terminal and Type
ssh friendusername@friendprivateip
example
ssh suhail@192.168.0.239
14. Friend 1 Will Get This Message From Terminal
15. Type Yes
How to Install SSH in Mobile Phone (Android)
Step 1: Install Termux App (Click Here)
Step 2: Type this Command
apt install openssh
Step 3: Type this Command
sudo apt update && sudo apt upgrade
Step 4: Type this command
ssh-keygen -t ed25519 -C "youremail@gmail.com"
Step 5: Press Enter 3 times until you get this
Step 6: Setting up Permission on SSH Folder and Keys
Type this command’s Line By Line
sudo chmod 700 .ssh
cd .ssh
sudo chmod 644 id_ed25519.pub
sudo chmod 600 id_ed25519
Step 7 : Setting Up SSH Access
- Friend 1 (A)
- Friend 2 (B)
If Friend 1 wants to Access Friend 2 System Files
Then Friend 1 Should Share his Public keys with Friend 2
How it Looks
- Friend 1 Will Go to His .ssh folder
- Friend 1 Wil Copy the public key (id_ed25519.pub)
- Friend 1 will share the public key to Friend 2
- Now Friend 2 Will Open his .ssh folder
- create a file name authorized_keys
To Create a File in Linux
touch authorized_keys
6. To Open the file
nano authorized_keys
7. Paste the Friend 1 Public Key in authorized_keysfile
8. Ctrl + O To Save the File
9. Ctrl + X To Exit it
10. Make Sure Both Friend 1 and Friend 2 are in Connected to Same Wifi Network
11. Now Friend 1 wants to Access Friend 2 File System
12. Friend 2 Should share his private ip and username of it
13. Friend 1 Should Open his Terminal and Type
ssh friendusername@friendprivateip
example
ssh suhail@192.168.0.239
14. Friend 1 Will Get This Message From Terminal
15. Type Yes