AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / computer / 问题 / 1537763
Accepted
Thufir
Thufir
Asked: 2020-04-02 00:11:59 +0800 CST2020-04-02 00:11:59 +0800 CST 2020-04-02 00:11:59 +0800 CST

Windows 上 OpenSSH 配置文件的位置

  • 772

如何通过 PowerShell在 Windows 的配置文件中设置主机名和端口?OpenSSH

在 Unix/Linux 上:

现在通过键入以下内容编辑或创建文件:

纳米 ~/.ssh/config

在这里,您可以设置特定于主机的配置选项。要指定新端口,请使用如下格式:

主机 remote_alias 主机名 remote_host 端口 port_num

这将允许您登录而无需在命令行上指定特定端口号。

https://www.digitalocean.com/community/tutorials/ssh-essentials-working-with-ssh-servers-clients-and-keys

windows command-line
  • 4 4 个回答
  • 62818 Views

4 个回答

  • Voted
  1. Martin Prikryl
    2020-04-04T01:25:27+08:002020-04-04T01:25:27+08:00

    OpenSSH 配置和密钥文件(包括config、known_hosts、authorized_keys、id_rsa等),在 *nix 上转到~/.ssh,在Win32-OpenSSH上转到%USERPROFILE%\.ssh.

    这通常是:

    C:\Users\username\.ssh
    
    • 12
  2. Best Answer
    LinkPhoenix
    2021-03-10T03:06:19+08:002021-03-10T03:06:19+08:00

    在带有 PowerShell 的 Windows 10 中,不会创建配置文件,因此我们必须自己创建它们。

    这个答案是通过:Windows 10 PRO 20H2 (Build 19042.804)
    以及来自官方 GitHub的最后一个 OpenSSH-Portable (v8.1.0.0p1-Beta)完成的

    注意 1:这里我展示了如何只配置文件夹.ssh中的配置文件“config” ,它应该在用户文件夹$HOME\.ssh中,因为它是必需的,通常在我看来,其他文件是自动创建的当一台安装 Open-SSH 服务器时。如果不是这种情况,只需调整命令行

    注意 2:有 Git for Windows 和 OpenSSH-portable 可能会导致代理配置出现问题,因此您应该知道它是 Windows 服务使用的 SSH-Agent

    您可以使用以下命令找出 Windows 服务使用了哪个 ssh-agent:

    Get-WmiObject win32_service | ?{$_.Name -like 'ssh-agent'} | select PathName
    

    如果该Get-WmiObject命令不再有效,您可以使用该Get-CimInstance命令,该命令应该是新版本 PowerShell 的最终继任者


    # Create the config file with Powershell
    New-Item -Path $HOME\.ssh\config -ItemType File
    
    # Open config File with Notepad
    C:\WINDOWS\System32\notepad.exe $HOME\.ssh\config
    
    # or Open file with Visual Code
    code $HOME\.ssh\config
    

    之后,您可以根据需要使用与 Linux 上相同的语法配置 SSH 配置文件

    小例子

    # Config for use specific key for github
    Host github.com
      HostName github.com
      User git
      IdentityFile ~/.ssh/id_ed25519_github
      IdentitiesOnly yes
    
    # For server 172.x.x.x
    Host 172.x.x.x
      User user
      Port 2121
      IdentityFile ~/.ssh/id_ed25519
      IdentitiesOnly yes
    
    # For all other servers
    Host *
            User root
    

    现在您可以像这样测试您的配置:

    # For Github
    
    ssh -T [email protected]
    
    # For other
    # It is possible not to put the user to check,
    # if you have indicated a specific user
    # in the conf file, to test if the configuration
    # will connect well with this user
    
    ssh -T 172.x.x.x
    

    如果 ssh 不起作用,这是因为您的环境变量中没有 OpenSSH 文件夹,如果您将OpenSSH
    Binary 安装在C:\
    名称是OpenSSH-Win64

    # PowerShell admin
    # Add folder OpenSSH to your System Environnement
    [System.Environment]::SetEnvironmentVariable('OPENSSH', 'C:\Program Files\OpenSSH-Win64', [System.EnvironmentVariableTarget]::Machine)
    

    其他命令

    # Generate EdDSA Key
    ssh-keygen.exe -t ed25519 -a 100 -o -C "[email protected]" -f "$HOME\.ssh\id_ed25519_example.com"
    
    # Config the SSH Agent service
    # For start the service when logon
    Set-Service ssh-agent -StartupType Automatic
    
    # Start the SSH Agent
    Start-Service ssh-agent
    
    # Restart service always when you change the config file
    Restart-Service ssh-agent
    
    # Add the key to the SSH Agent
    ssh-add $HOME\.ssh\id_ed25519_example.com
    
    • 9
  3. P O
    2022-10-22T14:52:10+08:002022-10-22T14:52:10+08:00

    简单回答问题“windows openssh CLIENT 的配置文件在哪里?”

    对于 Openssh 窗口 CLIENT C:\ProgramData\ssh\ssh.config

    请注意,此文件不会自动创建,您可以自己创建一个。该文件与sshD.config类似,它也位于那里,但为 Windows 上的 OpenSSH 服务器配置。

    另请注意,密码和密钥设置默认为无,因此您至少需要在ssh.config文件中进行设置:(+ 表示添加到任何现有条目):

    Ciphers +aes128-cbc,aes256-cbc,3des-cbc
    KexAlgorithms +diffie-hellman-group1-sha1
    HostkeyAlgorithms +ssh-rsa
    

    以上设置适用于 Cisco SSH 客户端到 Win SSH 服务器和 Win SSH 客户端到 Cisco SSH 服务器。对于其他人,您需要查看在发出缺少密码和密钥的 SSH 命令时返回的错误。

    例如,在 Win SSH 客户端上:

    PS C:\Users\poh> ssh 192.168.111.2

    Unable to negotiate with 192.168.111.2 port 22: no matching key exchange method found. Their offer: diffie-hellman-group1-sha1

    在 Cisco SSH 服务器上:(使用命令 - debug ip ssh all)

    *Mar  1 12:31:59.020: SSH2 0: no matching cipher found: client [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],
    *Mar  1 12:31:59.128: SSH0: Session disconnected - error 0x00
    

    所以根据错误,Win客户端需要ssh.config文件中的条目:

    Kex算法+diffie-hellman-group1-sha1

    • 1
  4. lewis hamilton
    2020-04-02T03:17:12+08:002020-04-02T03:17:12+08:00

    OpenSSH 安装后,执行一些额外的配置步骤。

    确保 OpenSSH 文件夹包含在系统路径环境变量中:

    C:\Windows\System32\OpenSSH\如果作为 Windows 可选功能 C:\Program Files\OpenSSH\安装 如果通过 OpenSSH 下载安装 将两个服务设置为自动启动:

    # PowerShell Admin
    # Config services sshd and ssh-agent
    # for start automatic when logon
    Set-Service sshd -StartupType Automatic
    Set-Service ssh-agent -StartupType Automatic
    

    如果您安装了带有可选功能的 OpenSSH,则 Windows 会创建一个新的防火墙规则,以允许通过端口 22 对 SSH 进行入站访问。如果您通过下载安装了 OpenSSH,则使用以下命令创建防火墙规则:

    # PowerShell Admin
    # Add FireWall Rules for OpenSSH Server
    New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' `
    -Enabled True -Direction Inbound -Protocol TCP `
    -Action Allow -LocalPort 22
    

    启动 sshd 服务以生成 SSH 密钥:

    # PowerShell Admin
    Start-Service sshd
    

    SSH 密钥和配置文件位于C:\ProgramData\ssh隐藏文件夹中。SSH 使用的默认 shell 是 Windows 命令 shell。这需要更改为 PowerShell:

    # PowerShell Admin
    New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell `
    -Value "C:\Program Files\PowerShell\6\pwsh.exe" -PropertyType String -Force
    

    现在,当您通过 SSH 连接到系统时,PowerShell Core 将启动并成为默认 shell。如果需要,您还可以将默认外壳程序设置为 Windows PowerShell。

    Windows 上的 OpenSSH 存在一个错误。它不适用于带有空格的路径,例如 PowerShell Core 可执行文件的路径!解决方法是创建一个符号链接来创建 OpenSSH 可以使用的路径:

    # PowerShell Admin
    New-Item -ItemType SymbolicLink -Path C:\pwsh -Target 'C:\Program Files\PowerShell\6'
    

    在 sshd_config文件中,取消注释以下行:

    PubkeyAuthentication yes
    PasswordAuthentication yes
    

    在其他子系统行之前添加此行:

    Subsystem  powershell C:\pwsh\pwsh.exe -sshs -NoLogo -NoProfile
    

    这告诉 OpenSSH 运行 PowerShell Core。

    注释掉这一行:

    AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys
    

    保存对 sshd_config 文件的更改后,重新启动服务:

    # PowerShell Admin
    Restart-Service sshd
    Start-Service ssh-agent
    

    对配置文件进行任何更改后,您需要重新启动 sshd 服务。

    • 0

相关问题

  • Python 的“pass”参数的批处理等价物是什么?

  • 禁用后无法启用 Microsoft Print to PDF

  • 在 Windows 上与 Docker 守护进程通信

  • 资源管理器侧面板中的桌面外壳快捷方式

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何减少“vmmem”进程的消耗?

    • 11 个回答
  • Marko Smith

    从 Microsoft Stream 下载视频

    • 4 个回答
  • Marko Smith

    Google Chrome DevTools 无法解析 SourceMap:chrome-extension

    • 6 个回答
  • Marko Smith

    Windows 照片查看器因为内存不足而无法运行?

    • 5 个回答
  • Marko Smith

    支持结束后如何激活 WindowsXP?

    • 6 个回答
  • Marko Smith

    远程桌面间歇性冻结

    • 7 个回答
  • Marko Smith

    子网掩码 /32 是什么意思?

    • 6 个回答
  • Marko Smith

    鼠标指针在 Windows 中按下的箭头键上移动?

    • 1 个回答
  • Marko Smith

    VirtualBox 无法以 VERR_NEM_VM_CREATE_FAILED 启动

    • 8 个回答
  • Marko Smith

    应用程序不会出现在 MacBook 的摄像头和麦克风隐私设置中

    • 5 个回答
  • Martin Hope
    CiaranWelsh 如何减少“vmmem”进程的消耗? 2020-06-10 02:06:58 +0800 CST
  • Martin Hope
    Jim Windows 10 搜索未加载,显示空白窗口 2020-02-06 03:28:26 +0800 CST
  • Martin Hope
    v15 为什么通过电缆(同轴电缆)的千兆位/秒 Internet 连接不能像光纤一样提供对称速度? 2020-01-25 08:53:31 +0800 CST
  • Martin Hope
    fixer1234 “HTTPS Everywhere”仍然相关吗? 2019-10-27 18:06:25 +0800 CST
  • Martin Hope
    andre_ss6 远程桌面间歇性冻结 2019-09-11 12:56:40 +0800 CST
  • Martin Hope
    Riley Carney 为什么在 URL 后面加一个点会删除登录信息? 2019-08-06 10:59:24 +0800 CST
  • Martin Hope
    zdimension 鼠标指针在 Windows 中按下的箭头键上移动? 2019-08-04 06:39:57 +0800 CST
  • Martin Hope
    jonsca 我所有的 Firefox 附加组件突然被禁用了,我该如何重新启用它们? 2019-05-04 17:58:52 +0800 CST
  • Martin Hope
    MCK 是否可以使用文本创建二维码? 2019-04-02 06:32:14 +0800 CST
  • Martin Hope
    SoniEx2 更改 git init 默认分支名称 2019-04-01 06:16:56 +0800 CST

热门标签

windows-10 linux windows microsoft-excel networking ubuntu worksheet-function bash command-line hard-drive

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve