Setting Up an SSH Server and Using
SSH for Remote System Access in Kali Linux: A Comprehensive Guide
Kali
Linux is a specialized distribution designed for cybersecurity professionals,
penetration testers, and ethical hackers. Setting up a Secure Shell (SSH)
server on Kali Linux enables secure remote access to systems, facilitating
tasks such as system administration, file transfers, and security testing in a
controlled environment. This professional article provides a detailed,
step-by-step guide to installing and configuring an SSH server using OpenSSH,
accessing it remotely, and utilizing SSH for system management. It includes
practical examples, usage scenarios, and ethical hacking considerations,
reflecting best practices as of September 2025.
Introduction
Secure
Shell (SSH) is a cryptographic network protocol that ensures secure
communication over an unsecured network, commonly used for remote command-line
login and file transfers. OpenSSH, the open-source implementation of SSH, is a
robust choice for setting up an SSH server on Kali Linux. This guide covers the
installation, configuration, and usage of an SSH server, demonstrating how to
log in remotely, execute commands, and transfer files securely. It also
includes ethical hacking techniques for testing SSH server security in
authorized environments.
Key Objectives
- Install and configure an
OpenSSH server on Kali Linux.
- Enable secure remote login
using SSH.
- Demonstrate SSH usage for
remote command execution and file transfers.
- Provide a practical example of
remote system management.
- Offer ethical hacking
techniques for testing SSH security.
- Highlight best practices for
secure SSH configuration.
Prerequisites
- Kali Linux 2025.x (or latest
version) installed.
- Root or sudo privileges.
- Internet connection for package
installation.
- Basic knowledge of Linux
commands and SSH.
- A controlled lab environment
(e.g., local machine or VM) for testing.
- Explicit permission for any
external testing (ethical hacking).
- A second machine (client) with
SSH client software (e.g., OpenSSH, PuTTY) for testing remote access.
- Static IP or hostname for the
Kali Linux machine (e.g., 192.168.1.100 or kali.example.com).
Installation and Setup
Step 1: Update Kali Linux
Ensure
the system is up-to-date to avoid compatibility issues:
sudo
apt update && sudo apt upgrade -y
This
updates the package index and installs the latest patches.
Step 2: Install OpenSSH Server
OpenSSH
is typically pre-installed on Kali Linux, but confirm and install if necessary:
sudo
apt install openssh-server -y
Start
and enable the SSH service to run on boot:
sudo
systemctl start ssh
sudo
systemctl enable ssh
Verify
the service is running:
sudo
systemctl status ssh
Check
that SSH is listening on port 22:
ss
-ant | grep 22
If
the service fails to start, check logs at /var/log/auth.log for errors.
Step 3: Configure the SSH Server
Edit
the SSH configuration file to enhance security:
sudo
nano /etc/ssh/sshd_config
Modify
or add the following settings:
Port
22
PermitRootLogin
no
PasswordAuthentication
yes
AllowUsers
kali
PubkeyAuthentication
yes
- Port 22: Default SSH port
(change to a non-standard port like 2222 for added security if desired).
- PermitRootLogin no: Disables
root login to prevent unauthorized access.
- PasswordAuthentication yes:
Allows password-based login (consider disabling for key-based
authentication only).
- AllowUsers kali: Restricts SSH
access to the kali user (replace with your username).
- PubkeyAuthentication yes:
Enables key-based authentication (configured later). Restart the SSH
service to apply changes:
sudo
systemctl restart ssh
Step 4: Configure Firewall (Optional)
If
using a firewall like UFW, allow SSH traffic:
sudo
ufw allow 22/tcp
sudo
ufw enable
Verify
the rule:
sudo
ufw status
Using SSH for Remote Access
Step 5: Test Local SSH Login
From
the Kali Linux machine, test SSH locally:
ssh
kali@localhost
Enter
the kali user’s password (default: kali unless changed). If successful, you’ll
be logged into a new session.
Step 6: Test Remote SSH Login
From
a second machine (client) with an SSH client installed:
- Linux/macOS: Use the terminal.
- Windows: Use PuTTY or Windows Subsystem for Linux (WSL).
Connect to the Kali machine (replace 192.168.1.100 with your Kali
machine’s IP):
ssh
kali@192.168.1.100
Enter
the password when prompted. If successful, you’ll access the Kali command line
remotely.
Step 7: Set Up Key-Based Authentication (Optional but
Recommended)
Key-based
authentication is more secure than passwords. On the client machine, generate
an SSH key pair:
ssh-keygen
-t rsa -b 4096
Accept
defaults (press Enter) or specify a custom file path. Copy the public key to
the Kali server:
ssh-copy-id
kali@192.168.1.100
Enter
the password when prompted. This copies the public key to ~/.ssh/authorized_keys
on the Kali machine. Test key-based login:
ssh
kali@192.168.1.100
You
should log in without a password. To enforce key-based authentication, edit
/etc/ssh/sshd_config:
sudo
nano /etc/ssh/sshd_config
Set:
PasswordAuthentication
no
Restart
SSH:
sudo
systemctl restart ssh
Practical Example: Remote System Management
Step 8: Remote Command Execution and File Transfer
Execute
Commands Remotely: From the client machine, run a
command on the Kali server:
ssh
kali@192.168.1.100 "whoami"
Output:
kali. Try system monitoring:
ssh
kali@192.168.1.100 "top -bn1 | head -n 5"
This
displays the top 5 processes.
Transfer
Files Using SCP: Copy a file from the client to the
Kali server:
scp
test.txt kali@192.168.1.100:/home/kali/
Copy
a file from the Kali server to the client:
scp
kali@192.168.1.100:/home/kali/test.txt .
Transfer
Files Using SFTP: Start an SFTP session:
sftp
kali@192.168.1.100
Upload
a file:
put
test.txt
Download
a file:
get
test.txt
Exit:
exit
Practical
Scenario: Set up a script to monitor system
logs remotely. On the Kali server, create a script:
nano
/home/kali/monitor_logs.sh
Add:
#!/bin/bash
tail
-n 10 /var/log/auth.log
Make
it executable:
chmod
+x /home/kali/monitor_logs.sh
Run
it remotely from the client:
ssh
kali@192.168.1.100 "/home/kali/monitor_logs.sh"
This
displays the last 10 lines of the SSH authentication log.
Ethical Hacking Techniques
Note: These techniques are for testing in controlled
environments (e.g., localhost or authorized lab setups) with explicit
permission. Unauthorized testing violates laws like the U.S. Computer Fraud and
Abuse Act or GDPR.
1. SSH Brute-Force Testing
Goal: Test for weak passwords. Steps:
- Install Hydra:
sudo
apt install hydra -y
- Attempt brute-forcing the kali
user:
hydra
-l kali -P /usr/share/wordlists/rockyou.txt ssh://192.168.1.100
- Monitor for successful logins.
- Mitigation: Disable password authentication
(PasswordAuthentication no), use key-based authentication, and limit login
attempts with Fail2Ban:
5. sudo
apt install fail2ban -y
sudo
nano /etc/fail2ban/jail.local
Add:
[sshd]
enabled
= true
port
= 22
maxretry
= 3
bantime
= 3600
Restart
Fail2Ban:
sudo
systemctl restart fail2ban
2. SSH Version Enumeration
Goal: Identify the SSH server version for potential
vulnerabilities. Steps:
- Use nmap to scan the SSH
service:
nmap
-sV -p 22 192.168.1.100
- Check for outdated OpenSSH
versions (e.g., pre-9.x).
- Mitigation: Keep OpenSSH updated:
sudo
apt install openssh-server -y
3. Sniffing Unencrypted SSH Traffic
Goal: Check for protocol vulnerabilities (e.g., SSHv1). Steps:
- Use Wireshark to capture
traffic:
sudo
wireshark &
- Filter for tcp.port == 22 and
attempt an SSH login.
- Check for plaintext data
(unlikely with SSHv2).
- Mitigation: Ensure /etc/ssh/sshd_config specifies:
Protocol
2
Restart
SSH: sudo systemctl restart ssh.
Best Practices
- Use Key-Based Authentication: Disable password authentication for enhanced
security.
- Change Default Port: Use a non-standard port (e.g., 2222) in
/etc/ssh/sshd_config to reduce automated attacks.
- Restrict Access: Use AllowUsers or a firewall to limit SSH access to
trusted IPs:
sudo
ufw allow from 192.168.1.0/24 to any port 22
- Enable Logging: Monitor /var/log/auth.log for unauthorized access
attempts.
- Regular Updates: Keep OpenSSH updated: sudo apt update && sudo
apt upgrade.
- Backup Keys: Store SSH private keys securely and back up
~/.ssh/authorized_keys.
- Ethical Testing: Test only in authorized environments and respect bug
bounty scopes.
Limitations
- Kali Linux Stability: Designed for testing, not production; consider Ubuntu
for production SSH servers.
- Security Risks: Misconfigured SSH servers are prime targets; secure
configurations are critical.
- Resource Usage: High SSH traffic can strain resources; monitor
performance.
- External Access: Requires proper firewall and NAT setup for external
connections, which may be restricted by VPS providers.
Conclusion
Setting
up an SSH server on Kali Linux with OpenSSH enables secure remote access for
system administration and testing. This guide demonstrated how to configure an
SSH server, log in remotely, execute commands, transfer files, and perform
ethical security tests. Always ensure you have permission for testing and follow
best practices to secure your server. For further learning, explore resources
like openssh.com, kali.org, or practice with tools like Metasploit.
To
convert this Markdown to .docx for your website, use Pandoc: pandoc
ssh-server-kali-linux-tutorial.md -o ssh-server-kali-linux-tutorial.docx.
Alternatively, paste into Microsoft Word or a CMS with Markdown support.

