OpenSSH on Windows: Installation, Configuration, and Usage Guide

WBOY
Release: 2024-03-08 09:31:08
forward
1117 people have browsed it

Windows 上的 OpenSSH:安装、配置和使用指南

For most Windows users, Remote Desktop Protocol (RDP) has always been the first choice for remote management because it provides a friendly graphical interface. However, for system administrators who require more granular control, SSH may better suit their needs. SSH allows administrators to interact with remote devices through the command line, making management more efficient. The advantages of SSH are its security and flexibility, making it easier for administrators to perform remote management and maintenance tasks, especially when dealing with large numbers of devices or performing automated tasks. So while RDP excels in terms of user-friendliness, for system administrators, SSH is superior in functionality and control.

Previously, Windows users needed third-party tools like PuTTY (open source) or Xshell (commercial) to use SSH. However, now Microsoft has launched an OpenSSH client and server built into Windows, providing users with a more convenient choice. This move brings a lot of convenience to users, who no longer need to rely on external software for easy SSH connections and data transfer. This means users can access remote servers more quickly and make secure file transfers without having to install and configure additional software. This move by Microsoft also shows that they are constantly improving and optimizing the Windows operating system to provide a better user experience and wider functionality. Windows users can now more easily take advantage of SSH technology, and

In Windows, OpenSSH is an optional feature that needs to be added manually, and the system will not install it automatically. This article will guide you on how to install, configure, and use the OpenSSH client and server in Windows 11 or Windows 10 (version 1809 and above).

What is OpenSSH?

OpenSSH is a tool for secure remote connections and computer management that uses encryption technology to ensure the security of communications. The main functions include remote login, command execution, file transfer, port forwarding, etc.

OpenSSH consists of two parts: client and server, including:

  • Client: used to connect to the remote server.
  • Server: Runs on the remote server and accepts client connection requests.

OpenSSH was originally developed for Linux systems and now also supports multiple operating systems including Windows and macOS.

Installing the OpenSSH client and/or server in Windows

Preparation conditions

Before you start installing OpenSSH, please make sure your computer meets the following conditions:

  • Operating system: Windows 11 or Windows 10 (version 1809 or higher).
  • PowerShell version: PowerShell 5.1 or above.
  • Administrator permissions: Installing OpenSSH requires administrator permissions.

Method 1: Install through "Settings"

1Use the Windows I shortcut key to open "Settings" and select "System" > "Optional Features".

2 Click "View Functions" and enter OpenSSH in the search box to filter.

3 Check as needed:

  • OpenSSH client: You can use the ssh command to connect to other SSH-enabled devices.
  • OpenSSH Server: Allows other devices to connect to your computer via SSH.

Add OpenSSH client and server

4 After selecting, click "Next", then click "Install" to start the installation process.

Method 2: Install using PowerShell

1Use the Windows R shortcut key to open the "Run" dialog box, enter powershell, and then press Ctrl Shift Enter to open the PowerShell window with administrator privileges.

2Execute the following command to view the OpenSSH installation status:

Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH*'
Copy after login

If NotPresent is returned, it means it is not installed; if Installed is returned, it means it is installed.

3Install OpenSSH client and server components as needed:

# 安装 OpenSSH 客户端
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0

# 安装 OpenSSH 服务器
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
Copy after login

Install OpenSSH client or server components

在 Windows 中配置 OpenSSH 服务器

当你在 Windows 上安装了 OpenSSH 服务器之后,需要进行一些配置才能接受连接:

1使用Windows + R快捷键打开「运行」对话框,输入powershell,然后按Ctrl + Shift + Enter以管理员权限打开 PowerShell。

2设置 SSHD 服务自动启动:

Set-Service -Name sshd -StartupType 'Automatic'
Copy after login

3启动 SSHD 服务:

Start-Service sshd
Copy after login

4检查 SSH 服务器是否在侦听 22 端口:

netstat -an | findstr /i ":22"
Copy after login

5确保 Windows Defender 防火墙允许 TCP 22 端口的入站连接:

Get-NetFirewallRule -Name *OpenSSH-Server* | select Name, DisplayName, Description, Enabled
Copy after login

配置 OpenSSH 服务器

如规则丢失或被禁用,可以创建新规则:

New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22

Copy after login

6(可选)如果要修改配置,如设置用户访问权限,可以编辑sshd_config配置文件:

Start-Process Notepad C:Programdatasshsshd_config
Copy after login

7根据需要修改配置文件,保存后关闭记事本。

OpenSSH 服务器配置文件可以在 sshd_config 手册页中找到。

编辑 sshd_config 配置文件

8完成更改后,重启 SSHD 服务应用配置:

Restart-Service sshd
Copy after login

重启 SSHD 服务

按照这些步骤,你的 Windows 就能通过 SSH 协议接受连接了。

使用 OpenSSH 客户端连接远程 SSH 服务器

在 Windows 中安装完 OpenSSH 客户端后,就可以立即与远程 SSH 设备建立连接:

1打开命令提示符或 Powershell,执行以下命令来检查 OpenSSH 客户端是否已经正确安装:

ssh
Copy after login

2使用以下命令连接到配置了 SSH 的服务器:

ssh [用户名]@[服务器IP]
Copy after login

使用 OpenSSH 客户端连接远程服务器

3首次连接时,会要求你输入密码。如果远程设备使用非标准 22 端口,需要指定端口号:

ssh 用户名@服务器名称 -p 端口号
Copy after login

Windows 上的 OpenSSH 是一个强大的工具,可用于远程管理设备和服务器。本文提供了详细的安装、配置和使用指南,帮助你充分利用 OpenSSH 的功能。

The above is the detailed content of OpenSSH on Windows: Installation, Configuration, and Usage Guide. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:mryunwei.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template