Skip to content

开启openssh

网站备注
官网
安装
免密登录

启动OpenSSH服务

打开服务管理器:

Win + R,输入 services.msc,然后按 Enter。 找到OpenSSH SSH Server服务:

在服务列表中找到OpenSSH SSH Server。 启动服务:

右键点击OpenSSH SSH Server,选择“启动”。 设置开机自启动:

右键点击OpenSSH SSH Server,选择“属性”。 在“启动类型”下拉菜单中选择“自动”,然后点击“应用”和“确定”。

配置防火墙

打开防火墙设置:

Win + R,输入 firewall.cpl,然后按 Enter。 允许应用通过防火墙:

点击“允许应用通过防火墙”。 点击“更改设置”,然后找到OpenSSH Server并确保它被允许通过防火墙。

配置SSH 默认情况下,OpenSSH服务器的配置文件位于 C:\ProgramData\SSH\sshd_config。你可以根据需要修改这个文件来调整SSH服务的配置。

编辑配置文件:

使用文本编辑器(如记事本)以管理员身份打开 C:\ProgramData\SSH\sshd_config 文件。 修改所需的设置,如端口号(默认为22)和认证方法等。 重新启动SSH服务:

在服务管理器中,右键点击OpenSSH SSH Server,选择“重新启动”。

传输文件

sh
scp local.txt Administrator@49.232.53.251:C:/Users/Administrator/Downloads/

免密登录

免密登录ssh的配置文件

sh
# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options override the
# default value.

#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

#HostKey __PROGRAMDATA__/ssh/ssh_host_rsa_key
#HostKey __PROGRAMDATA__/ssh/ssh_host_dsa_key
#HostKey __PROGRAMDATA__/ssh/ssh_host_ecdsa_key
#HostKey __PROGRAMDATA__/ssh/ssh_host_ed25519_key

# Ciphers and keying
#RekeyLimit default none

# Logging
#SyslogFacility AUTH
#LogLevel INFO

# Authentication:

#LoginGraceTime 2m
#PermitRootLogin prohibit-password
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

PubkeyAuthentication yes

# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
# but this is overridden so installations will only check .ssh/authorized_keys
AuthorizedKeysFile	.ssh/authorized_keys

#AuthorizedPrincipalsFile none

# For this to work you will also need host keys in %programData%/ssh/ssh_known_hosts
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes

# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no

# GSSAPI options
#GSSAPIAuthentication no

#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
#PermitTTY yes
#PrintMotd yes
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
#PermitUserEnvironment no
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS no
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none

# no default banner path
#Banner none

# override default of no subsystems
Subsystem	sftp	sftp-server.exe

# Example of overriding settings on a per-user basis
#Match User anoncvs
#	AllowTcpForwarding no
#	PermitTTY no
#	ForceCommand cvs server

# Match Group administrators
#        AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys

其实总共就保留了三条配置,其余都是注释掉:(不同版本的openssh server可能有所不同)

sh
PubkeyAuthentication yes
AuthorizedKeysFile	.ssh/authorized_keys
Subsystem	sftp	sftp-server.exe