This translation is older than the original page and might be outdated. See what has changed.

FIXME This page is not fully translated, yet. Please help completing the translation.
(remove this paragraph once the translation is finished)

SSH Access for Newcomers

默认情况下,OpenWRT设备始终侦听端口22上的SSH命令行访问. 要通过SSH连接到您的路由器, 您需要在终端仿真器中输入命令 ssh root@192.168.1.1 (对于路由地址 192.168.1.1).

第一次通过ssh访问路由器时,您可能会看到关于 RSA key fingerprint 的警告. 如果您确定这是OpenWrt设备的地址,只需键入 yes 然后按回车. 然后输入您给路由器的密码,如果这是初始设置,请按回车. 下面是一个会话示例:

$ ssh root@192.168.1.1                                                    <== 你输入这个
The authenticity of host '192.168.1.1 (192.168.1.1)' can't be established.
RSA key fingerprint is SHA256:4VbDA/MOc7inPiyllF5f0r3Q6iEx89ddKdhLGBovsiY.
Are you sure you want to continue connecting (yes/no)? yes                <== 和这个
Warning: Permanently added '192.168.1.1' (RSA) to the list of known hosts.
root@192.168.1.1's password:                                              <== 这里输入密码

BusyBox v1.28.4 () built-in shell (ash)

  _______                     ________        __
 |       |.-----.-----.-----.|  |  |  |.----.|  |_
 |   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
 |_______||   __|_____|__|__||________||__|  |____|
          |__| W I R E L E S S   F R E E D O M
 -----------------------------------------------------
 OpenWrt 18.06.2, r7676-cddd7b4c77
 -----------------------------------------------------

root@OpenWrt:~#                                                               <== 在此处键入下一个命令

要结束与你路由器的 ssh 会话 , 请键入 exit, 然后按回车. 本页的其余部分介绍了几种终端模拟器, 可用于Windows, Linux, 或 macOS 上访问OpenWrt设备.

Windows 终端是 Windows 10 或较早传统的进程 (两者都可以访问Windows Powershell, Windows 命令提示符, WSL Bash), Putty, Cmder, Smartty, 以及 WinSCP 都是允许您通过SSH连接到OpenWrt路由器的终端模拟器.

Windows Powershell and 命令提示符 两者都可以使用 Windows 10 默认的SSH 客户端. SSH 客户端是可选的windows功能, 必须启用,请阅读以下内容: Windows 10 上安装 OpenSSH

如果您已经安装了 WSL 发行版, SSH客户端通常会预装在其中.

如果你打开了 cmd.exe, powershell.exe 或者 wsl.exe 传统的进程终端. 否则, 您可以从商店安装最新的 Windows Terminal 并从那里选择这些 shells 中的任何一个.

  1. 打开上述任何终端模拟器并输入 ssh root@192.168.1.1 (“ssh” 是命令, “root” 是您要连接的OpenWrt用户, “192.168.1.1” 是 OpenWrt 默认 IP 地址)
  2. 将出现一条关于接受来自OpenWrt设备的新密钥的消息, 输入 “yes” 后并按回车.
    1. 如果由于某种原因,您重新安装了OpenWrt,那么设备将有一个不同的密钥,并且您会收到一个关于密钥不匹配的错误. 错误将说明在终端中复制粘贴删除旧密钥并继续的命令行. 执行并重试.
  3. 如果您想关闭会话,请输入 “exit”

Windows 10 可选的 SSH 特性还包括 SCP 客户端(通过SSH进入在OpenWrt中执行打开/编辑/下载/上传文件). 试试谷歌或度娘一些 SCP 教程来学习如何使用它. 否则, 使用 WinSCP,这对 SCP 新手来说更容易.

Powershell 7 提供SSH访问. 这里是7.0版的发布, 以及安装说明: https://devblogs.microsoft.com/powershell/announcing-PowerShell-7-0/

Putty给你命令行访问OpenWrt:

  1. https://www.putty.org下载Putty: 只需可选从 Alternative binary files 部分选择下载32位或64位 putty.exe 二进制文件.
  2. 在你的Windows上打开 putty.exe → 弹出Putty的登录窗口.
  3. 转到Putty登录窗口左侧的 Session 类别, 在右侧 Host Name (or IP address) 下的文本框输入OpenWrt设备的IP地址 (e.g. 192.168.1.1) , 保留默认提供的端口 22.
  4. 单击底部的 Open 按钮打开连接. 这将弹出一个shell窗口, 正在请求 login as. 使用您以前定义的OpenWrt密码作为 root 登录. 如果您尚未在 “root” 上设置密码, 则不会要求您输入密码.
  5. 完成后,您将登录到OpenWrt命令行.

WinSCP allows you to browse the OpenWrt file system in Windows Exlorer like GUI-style:

  1. Download WinSCP from https://winscp.net/eng/download.php, get the non-beta Installation package or portable executables and install or unzip them on your Windows client
  2. Start WinSCP.exe on your Windows client, WinSCP's login window will pop up
  3. Click on New Site on the left, then enter your OpenWrt device IP address (192.168.1.1) on the right side into Host name, keep the default port 22. In User name enter root, in Password, enter your root password (or leave blank, if you have not set a password yet)
  4. Click the Login at the bottom of the Window.
  5. Done. You now have an Exlorer-like view of your OpenWrt filesystem.

Editing OpenWrt config files with WINSCP's integrated GUI editor:
To edit a OpenWrt config file with WinSCP's GUI-based editor, just right-click the file in WinSCP and select Edit from the context menu.

Cmder for Windows is an open-source terminal emulator that runs on Windows. It is free to use and provides an easy “command line shell” that allows you to ssh into OpenWrt. Its attractive fonts and color scheme are easy on the eyes. The Full distribution is preferred (over the mini distribution), since it provides a bash emulation, with a Unix-y suite of commands.

  1. Download cmder from https://cmder.net/
  2. Unzip the cmder.zip file
  3. Open the Cmder folder, and double-click the Cmder icon. You'll see a Cmder window open similar to the image below.
  4. To ssh into the OpenWrt router at 192.168.1.1, type ssh root@192.168.1.1 then press Return

Smartty gives you command line access to OpenWrt and allows you to open/edit/download/upload files in OpenWrt, and is overall more modern and user-friendly than Putty (another tool detailed below):

  1. Download Smartty from http://sysprogs.com/SmarTTY/: choose “download” for the installer, or “portable version” if you want it as a standalone program that works without installation.
  2. after installation or after unzipping the archive, doubleclick on SmarTTY executable file.
  3. You will be greeted by a window with two choices, doubleclick on “setup a new SSH connection” (the other option is for serial connections, for usb-TTL dongles and somesuch you connect to the device's debug serial pins on the board, we won't use that now).
  4. The window changes into the SSH setup, write the following info:
    1. Host name: OpenWrt device IP address (default is 192.168.1.1 )
    2. User Name: root (this is the “administrator” and only user in default OpenWrt)
    3. Password: leave this blank for your first connection, then write the password you set up (either in Luci GUI or after your first SSH access)
  5. Click “Connect” button at the bottom, and you will now see a big terminal screen coming up
  6. A default OpenWrt firmware lacks the server component to allow you to open/edit/view/upoad/download files in Smartty, so after you have connected to the internet write opkg update && opkg install openssh-sftp-server to install it. If the next step fails, it might be necessary to reboot the OpenWrt device for this new service to start up properly.
  7. Now you can click on File → Open a Remote File to open a popup that shows the filesystem of the OpenWrt device, and you can navigate in it and open text files for example as normal (they will open in a SmarTTY text editor window)
  8. If you want to upload or download files to/from a specific folder in the device, you can click on SCP menu and choose the most appropriate action from there.

After the first time you connected to a device, Smartty saved a profile, so you can connect again to the same device (at that IP address with that password) by just doubleclicking its icon on the first window you see when starting Smartty. You can right-click on this profile icon to edit it again, if needed.

All Linux distributions provide a command-line ssh client as part of the default installation.

  1. Open a terminal emulator and write ssh root@192.168.1.1 (“ssh” is the command, “root” is the OpenWrt user you are connecting to, and “192.168.1.1” is OpenWrt default IP)
  2. there will be a message about accepting a new key from the OpenWrt device, write “yes” and press Enter key.
    1. If for some reason you have reinstalled OpenWrt the device will have a different key and you get an error about key mismatch. The error will state what is the command line to copy-paste in your terminal to delete the old key and proceed.
  3. if you want to close the session, write “exit”

Linux also usually has SCP clients (to open/edit/download/upload files in OpenWrt), which may or may not be installed by default. You need to look up your distro's documentation or search with your package management interface for “SCP” to find where it is and its current installation status. Read its integrated manual (“man scp” for example is for the command line SCP client) or google some tutorials to learn how to use it.

On macOS (formerly Mac OSX) any terminal emulator will allow you to ssh. There several terminal emulators:

  1. Terminal - The macOS built-in terminal program. Find it in /Applications/Utilities
  2. iTerm2 https://iterm2.com/ a much-enhanced terminal program. Donation-ware - it's worth it.

To ssh into your OpenWrt router at 192.168.1.1, type ssh root@192.168.1.1, then press Return.

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
  • Last modified: 2020/10/14 01:40
  • by guyezi