如何设置FRP

这个是宝塔的教程帖

https://www.bt.cn/bbs/forum.php?mod=viewthread&tid=137773&highlight=FRP

③frp配置。

  • frps(放到云服务器上)
[common]
bind_addr = 0.0.0.0

#服务端运行端口,可以自定义1-65535之间即可

bind_port = 9527 \\和frps一致

#dashboard WEB控制台登录用户名,可以自定义

dashboard_user = xxx \\仪表盘用户名

#dashboard WEB控制台登录密码

dashboard_pwd = xxx \\仪表盘用户名

#dashboard WEB控制台端口,可以自定义1-65535之间即可,启动后通过浏览器访问如http://ip:8080

dashboard_port = 52012 \\云服务器开一个端口用于仪表盘

#设置客户端token,对应客户端的token配置,作用类似密码验证,可以自定义

token = xxx \\密码

vhost_http_port = 80 \\不变
  • 服务器端启动.bat
@echo off
if "%1" == "h" goto begin
mshta vbscript:createobject("wscript.shell").run("""%~0"" h",0)(window.close)&&exit
:begin
REM
cd C:\Users\Administrator\Desktop\frps
.\frps.exe -c frps.ini
  • 服务器端停止.bat
taskkill /f /im frps.exe
  • frpc(放到需要内网映射的电脑上)
[common]
server_addr=10.10.10.10 \\购买的云服务器的IP地址
server_port = 9527 \\云服务器开一个端口监管frp,注意客户端frpc中也要一致
token = xxx \\随便写个密码
pool_count = 5 \\随便写

# [range:services_win]
# type = tcp
# local_ip = 127.0.0.1
# local_port = 2222
# remote_port = 52013

[range:services_wsl]
type = tcp
local_ip = 127.0.0.1 \\不变,本机ip
local_port = 9000 \\客户端的ssh端口,在客户端ssh配置里将默认的22号改成9000
remote_port = 52014 \\远程的SSH端口,在云服务器中记得打开52014端口噢

# [range:services3]
# type = tcp
# local_ip = 127.0.0.1
# local_port = 2222
# remote_port = 52012
  • 客户端启动.bat
@echo off
if "%1" == "h" goto begin
mshta vbscript:createobject("wscript.shell").run("""%~0"" h",0)(window.close)&&exit
:begin
REM
cd D:\Frp\frp
.\frpc.exe -c frpc.ini
  • 客户端停止.bat
taskkill /f /im frpc.exe

④ 打开云服务器中的服务,开启ssh服务,刷新或重启服务。使得frp配对成功。

⑤ 配置ssh,进入客户端的sshd配置文件,vim /etc/ssh/sshd_config。

#       $OpenBSD: sshd_config,v 1.103 2018/04/09 20:41:22 tj Exp $

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

# This sshd was compiled with PATH=/usr/bin:/bin:/usr/sbin:/sbin

# 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.

Include /etc/ssh/sshd_config.d/*.conf

Port 9000 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\将22改成9000
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key
#HostKey /etc/ssh/ssh_host_ed25519_key

# Ciphers and keying
#RekeyLimit default none

# Logging
#SyslogFacility AUTH
#LogLevel INFO

# Authentication:

#LoginGraceTime 2m
PermitRootLogin yes   \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\yes
#StrictModes yes
#MaxAuthTries 6
MaxSessions 50

PubkeyAuthentication yes \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\yes

AllowUsers *
# Expect .ssh/authorized_keys2 to be disregarded by default in future.
#AuthorizedKeysFile     .ssh/authorized_keys .ssh/authorized_keys2

#AuthorizedPrincipalsFile none

#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody

# For this to work you will also need host keys in /etc/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 no   \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\no
#PermitEmptyPasswords no

# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
iChallengeResponseAuthentication no  \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\no

# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no

# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
UsePAM yes  \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\yes

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

# no default banner path
#Banner none

# Allow client to pass locale environment variables
AcceptEnv LANG LC_*

# override default of no subsystems
Subsystem       sftp    /usr/lib/openssh/sftp-server

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

⑥ 重启客户端的sshd服务。

sudo /etc/init.d/ssh restart
sudo /etc/init.d/ssh start #开启ssh服务sudo service ssh status #查看ssh服务状态
sudo /etc/init.d/ssh stop #关闭ssh服务sudo service ssh status #查看ssh服务状态
或:
sudo systemctl restart sshd
sudo systemctl status sshd

⑦ 配置ssh密钥:

笔记本和公司的电脑之间配置ssh密钥即可,也就是不管云服务器了。

笔记本生成ssh密钥,然后将公钥拷贝到公司电脑的ubuntu系统里的~/.ssh/authorized_keys文件里,没有就创建一个。

然后修改密钥文件的权限:

chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

重启ssh服务

sudo /etc/init.d/ssh restart

至此,所有配置以完成。在笔记本上运行

ssh 公司电脑用户名@10.10.10.10(公网ip) -p9000(公网端口)

就可以连接了。

© 版权声明

相关文章

暂无评论

暂无评论...