🔹 Step 1: Install Required Packages

📥 Install OpenSSH Server (for self-hosting your Linux distro) or Dropbear (a lightweight SSH server and client).

To install OpenSSH Server:

  • Debian/Ubuntu:
sudo apt install openssh-server -y
  • Arch Linux:
sudo pacman -S openssh
  • Fedora:
sudo dnf install openssh-server
  • CentOS/RHEL:
sudo yum install -y openssh-server

🔹 Note: For Dropbear, replace openssh-server with dropbear in the installation commands.


🔹 Step 2: Check SSH Server Status

🛠️ Run the following command to check the status:

  • If you are using Dropbear:
sudo systemctl status dropbear
  • If you are using OpenSSH Server:
sudo systemctl status ssh

Check status

⚡ In the further steps, we will continue with OpenSSH. Everything will be the same for Dropbear.


🔹 Step 3: Start the SSH Server (If Inactive)

🚀 If the status shows inactive, start the server using:

sudo systemctl start ssh

(Replace "start" with "stop" to stop the server.)

starting and checking status of ssh server

🔹 Step 4: Open a Terminal for Connection

🖥️ Open a new terminal,PuTTY, Termux, or any other terminal to connect to the host computer.

Here we are using termux

🔹 Step 5: Find the Host's IP and Username

🌐 To get the IP address, run:

ifconfig

🔍 Search for "inet"—the digits following the colon are the user’s IP(private).

check your private ip

👤 To get the username, run:

whoami

check username

📌 Note:

  • If the client and host are on the same network (e.g., same WiFi router), use the local IP to connect.
  • If the client and host are on different networks (e.g., the host is on home WiFi and the client is on cellular data or different WiFi), use the public IP of the host. Get it by visiting WhatIsMyIP.com on the host machine.
  • Ensure port forwarding for port 22 on your host machine’s WiFi router to allow the connection.
  • Ignore port forwarding if on the same network, as you can directly connect using the host machine’s private IP.

Retrieve your public ip

Note: My host is connected to a WiFi router, and my client machine (phone) is on a cellular network, so I need to consider my public IP.

🔹 Step 6: Connect to the Remote Server

🔑 Run the following command:

ssh username@ip

connecting to host
🔐 You will be asked for a password to run the sudo command and another password to log into the server.


🔹 Step 7: Log into the Server

💻 Now, connect to the server using the command from Step 6, replacing it with the host’s username and IP, then enter the password.

Type Yes, here!!! ✅🎯

Loggin in

Enter the password and hit Enter 🔑➡️⏎

type password

🔹 Step 8: Verify the SSH Connection

🔍 To check if the connection is active, run:

who

check active connected users
📋 It will show a list of users currently using your distro.
Look for something like /pts/0 or /pts/any_number—if it's present, your session is active, or a user is logged in.


🔹 Step 9: Kill an Active SSH Connection (If Needed)

⚠️ To terminate a particular SSH session, run:

sudo fuser -k /dev/pts/

🔌 This will disconnect the user from the SSH session.

killing an user session

🔹 Step 10: Confirm Disconnection

🔁 Again, check the active connections using the who command.(Look at the above screenshot 👆👆👆)

A message appears showing the connection has been closed 👇👇👇

ensuring proper disconnection

🔹 Step 11: Logout or Stop the SSH Server

🔓 To log out, type:

exit

run the command to exit

Successfully exited!! ✅🚪

finally exited
⛔ To stop the SSH server, run the command listed in Step 2.


Thanks for reading! 🎉 You've now set up an SSH server, connected remotely, and managed your sessions. Stay secure by using SSH keys (more on that in my next post—stay tuned!), disabling root login, and using firewalls or VPNs.

If connecting over the internet, be mindful of your public IP, enable port forwarding, and use strong passwords or SSH keys.

Got questions? Drop a comment! Don't forget to follow for more tech guides. Happy SSH-ing! 🚀🔑