| Next revisionBoth sides next revision |
| zh:docs:guide-quick-start:sshadministration [2020/10/14 01:40] – created guyezi | zh:docs:guide-quick-start:sshadministration [2023/12/23 09:59] – Synced with en page heybrowhatsup |
|---|
| |
| ======SSH Access for Newcomers====== | ======SSH Access for Newcomers====== |
| 默认情况下,OpenWRT设备始终侦听端口22上的SSH命令行访问. 要通过SSH连接到您的路由器, 您需要在终端仿真器中输入命令 ''ssh root@192.168.1.1'' (对于路由地址 192.168.1.1). | 默认情况下,OpenWrt 设备始终侦听端口''22/tcp''上的SSH命令行访问。 |
| | 要通过SSH连接到您的路由器, 您需要在终端仿真器中输入以下命令(对于路由地址 192.168.1.1): |
| |
| 第一次通过ssh访问路由器时,您可能会看到关于 //RSA key fingerprint// 的警告. 如果您确定这是OpenWrt设备的地址,只需键入 ''yes'' 然后按回车. 然后输入您给路由器的密码,如果这是初始设置,请按回车. 下面是一个会话示例: | <code bash> |
| | ssh root@192.168.1.1 |
| | </code> |
| | |
| | 第一次通过ssh访问路由器时,您可能会看到关于 //RSA key fingerprint// 的警告. 如果您确定这是 OpenWrt 设备的地址,只需键入 ''yes'' 然后按回车. 然后输入您给路由器的密码,如果这是初始设置,请按回车. 下面是一个会话示例: |
| <code> | <code> |
| $ ssh root@192.168.1.1 <== 你输入这个 | $ ssh root@192.168.1.1 <== 你输入这个 |
| |
| 要结束与你路由器的 //ssh 会话// , 请键入 ''exit'', 然后按回车. | 要结束与你路由器的 //ssh 会话// , 请键入 ''exit'', 然后按回车. |
| 本页的其余部分介绍了几种终端模拟器, 可用于Windows, Linux, 或 macOS 上访问OpenWrt设备. | 本页的其余部分介绍了几种终端模拟器, 可用于 Windows, Linux, 或 macOS 上访问 OpenWrt 设备. |
| =====Windows Terminal Emulators===== | |
| Windows 终端是 Windows 10 或较早传统的进程 (两者都可以访问Windows Powershell, Windows 命令提示符, WSL Bash), Putty, Cmder, Smartty, 以及 WinSCP 都是允许您通过SSH连接到OpenWrt路由器的终端模拟器. | |
| |
| ====使用Windows 10内置终端==== | ===== Windows Terminal Emulators ===== |
| | 可使用 Windows 终端或传统的 PowerShell、Command Prompt、ConHost 或 WSL Bash。PuTTY、MinGW(与 Git 一起安装)、Cmder、SmarTTY 和 WinSCP 等第三方程序也是可以提供 SSH 进入 OpenWrt 路由器的终端模拟器。 |
| |
| **Windows Powershell** and **命令提示符** 两者都可以使用 Windows 10 默认的SSH 客户端. SSH 客户端是可选的windows功能, 必须启用,请阅读以下内容: [[https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse|Windows 10 上安装 OpenSSH ]] | ==== Windows 10/11 内置终端 ==== |
| | [[https://github.com/microsoft/terminal|Windows 终端]]、PowerShell 和命令提示符允许使用 SSH 客户端。该客户端现在默认可用,但如果你的 Windows 版本较老,你可以按照本指南[[https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse|启用 SSH]]。 |
| |
| 如果您已经安装了 WSL 发行版, SSH客户端通常会预装在其中. | 如果您已经安装了 [[https://docs.microsoft.com/en-us/windows/wsl/install|WSL 发行版]],SSH客户端通常会预装在其中。 |
| |
| 如果你打开了 ''cmd.exe'', ''powershell.exe'' 或者 ''wsl.exe'' 传统的进程终端. 否则, 您可以从商店安装最新的 [[https://www.microsoft.com/store/productId/9N0DX20HK701|Windows Terminal]] 并从那里选择这些 shells 中的任何一个. | 如果你打开了 ''cmd.exe'', ''powershell.exe'' 或者 ''wsl.exe'' ,传统的 ConHost 终端就会打开。 否则, 您可以从商店安装最新的 [[https://www.microsoft.com/store/productId/9N0DX20HK701|Windows Terminal]] 并从那里选择这些 shells 中的任何一个. |
| - 打开上述任何终端模拟器并输入 ''ssh root@192.168.1.1'' ("ssh" 是命令, "root" 是您要连接的OpenWrt用户, "192.168.1.1" 是 OpenWrt 默认 IP 地址) | - 打开上述任何终端模拟器并输入 ''ssh root@192.168.1.1'' ("ssh" 是命令, "root" 是您要连接的OpenWrt用户, "192.168.1.1" 是 OpenWrt 默认 IP 地址) |
| - 将出现一条关于接受来自OpenWrt设备的新密钥的消息, 输入 "yes" 后并按回车. | - 将出现一条关于接受来自OpenWrt设备的新密钥的消息, 输入 "yes" 后并按回车. |
| Windows 10 可选的 SSH 特性还包括 SCP 客户端(通过SSH进入在OpenWrt中执行打开/编辑/下载/上传文件). 试试谷歌或度娘一些 SCP 教程来学习如何使用它. 否则, 使用 [[:docs:guide-quick-start:sshadministration#using_winscp|WinSCP]],这对 SCP 新手来说更容易. | Windows 10 可选的 SSH 特性还包括 SCP 客户端(通过SSH进入在OpenWrt中执行打开/编辑/下载/上传文件). 试试谷歌或度娘一些 SCP 教程来学习如何使用它. 否则, 使用 [[:docs:guide-quick-start:sshadministration#using_winscp|WinSCP]],这对 SCP 新手来说更容易. |
| |
| ====使用 Powershell 7==== | ==== Powershell ==== |
| | [[https://docs.microsoft.com/en-us/powershell/scripting/overview?view=powershell-7.2|Powershell]] 提供 SSH 访问。 |
| |
| **Powershell 7** 提供SSH访问. 这里是7.0版的发布, 以及安装说明: https://devblogs.microsoft.com/powershell/announcing-PowerShell-7-0/ | ==== Windows Subsystem for Linux (WSL) ==== |
| | Windows Subsystem for Linux 是在 Windows 上直接运行所选 Linux 环境(包括大多数命令行工具、实用程序和应用程序)的便捷方法。有关如何在 Windows 10 上安装 WSL 的详细步骤,请参阅微软的文档:https://docs.microsoft.com/en-us/windows/wsl/install-win10 |
| |
| ====使用 putty==== | ==== putty ==== |
| Putty给你命令行访问OpenWrt: | Putty给你命令行访问OpenWrt: |
| - 从[[https://www.putty.org]]下载Putty: 只需可选从 ''Alternative binary files'' 部分选择下载32位或64位 ''putty.exe'' 二进制文件. | - 从[[https://www.putty.org]]下载Putty: 只需可选从 ''Alternative binary files'' 部分选择下载32位或64位 ''putty.exe'' 二进制文件. |
| - 完成后,您将登录到OpenWrt命令行. | - 完成后,您将登录到OpenWrt命令行. |
| |
| ====使用 WinSCP==== | Setting up key-based authentication. |
| WinSCP allows you to browse the OpenWrt file system in Windows Exlorer like GUI-style: | |
| - 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 | |
| - Start ''WinSCP.exe'' on your Windows client, WinSCP's login window will pop up | |
| - 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) | |
| - Click the ''Login'' at the bottom of the Window. | |
| - Done. You now have an Exlorer-like view of your OpenWrt filesystem. | |
| |
| **Editing OpenWrt config files with WINSCP's integrated GUI editor:**\\ | - Generate a key pair using ''puttygen.exe''. Save the private key to the PC and add the public key to ''/etc/dropbear/authorized_keys'' on your OpenWrt device. |
| 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. | - Connection -> SSH -> Auth: In the box "Authentication Parameters" under "Private key file for Authentication" state the path to your private key file for this connection (e.g. the ''openwrt.ppk'' file you created before). Best is to click "Browse..." and select the file via the file dialog. |
| |
| ====Using Cmder==== | Automating connections. |
| **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. | |
| |
| - Download cmder from [[https://cmder.net/]] | - Connection -> Data: In the box "Login details" enter the "Auto-login username" which is ''root''. |
| - Unzip the //cmder.zip// file | - Load, save or delete a stored session, enter ''openwrt.lan'' in Saved Sessions and click the Save button. |
| - Open the Cmder folder, and double-click the {{:media:docs:howto:cmdericon.png?16|}} Cmder icon. You'll see a Cmder window open similar to the image below. | - To make a PuTTY shortcut with an automatic login, create one and append the saved session with an ''@'' sign, for example call PuTTY with: ''putty.exe @openwrt.lan'' |
| - To ssh into the OpenWrt router at 192.168.1.1, type ''ssh root@192.168.1.1'' then press Return | |
| {{:media:docs:howto:cmder.png?1592|}} | |
| |
| ====Using Smartty==== | ==== WinSCP ==== |
| 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): | WinSCP allows you to browse the OpenWrt file system in Windows Exlorer like GUI-style. |
| |
| - 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. | - 下载 [[https://winscp.net/eng/download.php|WinSCP]],获取非 Beta 版 ''安装包'' or ''便携式可执行文件'' 并将其安装或解压到 Windows 上。 |
| | - 启动 ''WinSCP.exe'', WinSCP 的登录窗口将弹出。 |
| | - Click on ''New Site'' on the left, ensure ''File protocol'' is set to **scp** 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) |
| | - 点击窗口底部的登录。 |
| | - 完成。 现在,您可以用类似 Exlorer 的方式查看 OpenWrt 文件系统了。 |
| | |
| | 使用 WinSCP 集成的 GUI 编辑器编辑 OpenWrt 配置文件。 |
| | |
| | - 要使用 WinSCP 基于 GUI 的编辑器编辑 OpenWrt 配置文件,只需右键单击 WinSCP 中的文件,然后从上下文菜单中选择 ''编辑''。 |
| | |
| | ==== Cmder ==== |
| | 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. |
| | |
| | - Download [[https://cmder.net/|Cmder]]. |
| | - Unzip the //cmder.zip// file. |
| | - Open the Cmder folder, and double-click the Cmder icon. You'll see a Cmder window open similar to the image below. |
| | - To ssh into the OpenWrt router at 192.168.1.1, type ''ssh root@192.168.1.1'' then press Return. |
| | |
| | ==== SmarTTY ==== |
| | 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). |
| | |
| | - Download [[http://sysprogs.com/SmarTTY/|SmarTTY]], choose "download" for the installer, or "portable version" if you want it as a standalone program that works without installation. |
| - after installation or after unzipping the archive, doubleclick on **SmarTTY** executable file. | - after installation or after unzipping the archive, doubleclick on **SmarTTY** executable file. |
| - 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). | - 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). |
| - **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) | - **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) |
| - Click "Connect" button at the bottom, and you will now see a big terminal screen coming up | - Click "Connect" button at the bottom, and you will now see a big terminal screen coming up |
| - 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. | - 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. |
| - 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) | - Now you can click on **File -> Open a Remote File** to open a popup that shows the file system 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) |
| - 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. | - 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. | 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. |
| |
| =====Linux Terminal Emulators===== | ===== Linux terminal emulators ===== |
| All Linux distributions provide a command-line ssh client as part of the default installation. | All Linux distributions provide a command-line ssh client as part of the default installation. |
| |
| - if you want to close the session, write "exit" | - 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. | Linux also usually has SCP/SFTP clients (to open/edit/download/upload files in OpenWrt), which may or may not be installed by default. |
| 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. | You need to look up your distro's documentation or search with your package management interface for "scp" and "sftp" to find where it is and its current installation status. |
| | Read [[man>scp|scp manual]] for the command line SCP client or google some tutorials to learn how to use it. |
| | |
| | ==== Midnight Commander ==== |
| | [[https://midnight-commander.org/|Midnight Commander]] is Norton Commander like file manager that works on Linux and macOS. |
| | You can access remote files on OpenWrt via mc: |
| | |
| | - Press 'F9' |
| | - Select 'Left' panel config |
| | - Select 'Shell link' |
| | - Input 'root@192.168.1.1/' and press OK |
| | - Now you'll see list of files and directories in root of OpenWrt |
| | |
| | Internally it works over [[wp>Files_transferred_over_shell_protocol|scp like protocol FISH]] so it not needs for installed SFTP server. |
| | |
| | ===== macOS terminal emulators ===== |
| | On macOS (formerly Mac OSX) any terminal emulator will allow you to ssh. |
| | |
| | - Terminal - 内置的终端程序,可在 /Applications/Utilities 中找到。 |
| | - [[https://iterm2.com/|iTerm2]] 是一款功能更强大的终端程序,捐赠软件,值得购买。 |
| |
| =====macOS Terminal Emulators ===== | 要 ssh 进入位于 192.168.1.1 的 OpenWrt 路由器,请键入 ''ssh root@192.168.1.1'',然后按 Return 键。 |
| On macOS (formerly Mac OSX) any terminal emulator will allow you to ssh. There several terminal emulators: | |
| |
| - Terminal - The macOS built-in terminal program. Find it in /Applications/Utilities | ===== ChromeOS terminal emulator ===== |
| - iTerm2 [[https://iterm2.com/]] a much-enhanced terminal program. Donation-ware - it's worth it. | 在 [[wp>ChromeOS]] 上, [[https://chrome.google.com/webstore/detail/secure-shell/iodihamcpbpeioajjeobimgagajmlibd|安全外壳 (SSH)]] 可以让你使用 SSH。 |
| |
| To ssh into your OpenWrt router at 192.168.1.1, type ''ssh root@192.168.1.1'', then press Return. | |