Configuring SSH on OpenWRT Router: A Step-by-Step Guide
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.
To check if SSH is installed, use this command in your router's terminal:
opkg list-installed | grep sshd
If SSH is installed, you'll see it listed. If not, install it using:
opkg update
opkg install dropbear
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:
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
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 "
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.