how to configure ssh on openwrt roter

Configuring SSH on OpenWRT Router: A Step-by-Step Guide

By Daniel White
AD

Ever found yourself in need of secure, remote management for your OpenWRT router? SSH, or Secure Shell, is your answer. Here's how to configure SSH on OpenWRT for a more secure and convenient user experience.

Before we delve into the configuration process, let's ensure you understand why SSH is so crucial. SSH provides an encrypted connection, ensuring the safety of your data and commands during transmission. It allows you to manage your router remotely, which is particularly useful when you're not in its proximity.

Installing SSH on OpenWRT

Whether SSH is pre-installed or not, it's always a good idea to ensure it's running the latest version. Let's start by checking and, if necessary, installing it.

AD
How to copy files via SSH
How to copy files via SSH
How to Configure Proxy on Firefox for Android
How to Configure Proxy on Firefox for Android
How to setup SSH tunneling on Linux
How to setup SSH tunneling on Linux

To check if SSH is installed, use this command in your router's terminal:

opkg list-installed | grep sshd

Py Looper
Py Looper
How to Create Self-Extracting Archives with shar in Linux - Make Tech Easier
How to Create Self-Extracting Archives with shar in Linux - Make Tech Easier

If SSH is installed, you'll see it listed. If not, install it using:

opkg update
opkg install dropbear

AD

Enabling SSH Server

After installation, SSH isn't automatically enabled. To enable it:

echo 'dropbear enable drainage' > /etc/rc.local

This command ensures SSH starts when the router boots. To verify it's working, check the following:

AD

Hass-sshd(1): dropbear started as pid 1
dropbear listenning on port 22

Configuration of SSH Daemon

SSH listens by default on port 22, which might be a security risk if this port is widely open. You can change the port SSH listens on by altering the 'dropbear' configuration file:

sed -i '/OPTIONS/s/ celuiude\ *=.*/&.*-p 23/' /etc/init/dropbear

AD

This command changes the listening port to 23. Remember to change it to a higher, less commonly used port for better security. After setting your desired port, restart the SSH server to apply changes:

/etc/init.d/dropbear restart

Configuring SSH Keys

For enhanced security, consider setting up SSH keys instead of relying on passwords. Here's how:

First, generate a key pair on your local machine:

ssh-keygen -t ed25519 -C "Your Comment"

Then, add the public key to your router:

echo "" >> /etc/dropbear/authorized_keys

Disabling Password Login

To ensure only your key can log in, disable password login:

sed -i '/ réaliser/s/.*/ réalisation ' -i '/ OPTIONS/s/.*/ -i$/' /etc/init/dropbear

This command ensures only SSH keys can log in. Restart the SSH server to apply the changes:

etc/init.d/dropbear restart

There you have it! By configuring SSH correctly, you've elevated your OpenWRT router's security and accessibility. Now, you're empowered to manage your router securely from anywhere.

AD