2022-09-19建站0
请注意,本文编写于 251 天前,最后修改于 239 天前,其中某些信息可能已经过时。

目录

nps 是什么?
服务端 - Linux 下载和安装
服务端的配置 - 安全第一

看完本文会得到什么

  1. 了解 nps 是什么,他能做什么,有什么好玩的?
  2. 在自己公网服务器上安装 nps 服务端

nps 是什么?

它是某几位开源大神写的一个网络组件,它致力于实现一个需求

让你家里的电脑或者是硬盘,或者是打印机,能够让你不在家的时候,用你的手机或者是笔记本电脑,也可以安全的直接操作和传输文件,尤其是当你想把重要的,很私密的信息保存到自己家里的电脑上时,nps 就可以帮助你实现这些需求。

之所以会有这种需求是因为并不是所有用户都相信公共的文件存储服务(网盘)的底线,尤其是在恶劣的竞争中,很多厂商承诺无限存储空间,但是又卡住你下载速度的脖子,让你付费,恰烂钱,吃相特别难看。而且有时候,你如果能在外面直接通过 windows 的远程登录自己的电脑也是一种刚需,所以 nps 以及之前的很多相关的开源项目就渐渐出现,再次感谢这些极具开源精神的大神,再次拜谢。

服务端 - Linux 下载和安装

首先登录到远端的服务器上:

$ ssh [email protected](请填写你自己机器的公网 IP)

如果你不是 root 用户名,也无关紧要,但是你一定得知道 root 的密码,否则之后执行 sudo 高权限操作会失败,nps 是无法使用的。

然后在你此刻正在使用的电脑浏览器上打开 nps 项目的 Github Release 页面,获取最新发布的版本,以当前最新的 2021 年 4 月 8 号发布的版本为例,通过 wget 的方式在服务器上下载这个安装包(不是在你本机电脑执行如下命令,注意!!!)

$ wget https://github.com/ehang-io/nps/releases/download/v0.26.10/linux_amd64_server.tar.gz

然后解压这个 tar 包

$ tar -zxvf linux_amd64_server.tar.gz

紧接着要安装这个包,

$ sudo ./nps install

接下来你会看见如下小部分截图

2022/09/19 10:53:01 install ok!
2022/09/19 10:53:01 Static files and configuration files in the current directory will be useless
2022/09/19 10:53:01 The new configuration file is located in /etc/nps you can edit them
2022/09/19 10:53:01 You can start with:
nps start|stop|restart|uninstall|update or nps-update update

恭喜你,第一步安装已经结束了。

服务端的配置 - 安全第一

$ sudo nps start

注意安装之后界面显示的那一段话

2022/09/19 10:53:01 The new configuration file is located in /etc/nps you can edit them

意思就是告诉你,配置文件在 /etc/nps 这个目录下,我们要去修改一下。

真正需要修改的文件是 /etc/nps/conf/nps.conf

它默认的配置如下

appname = nps
#Boot mode(dev|pro)
runmode = dev

#HTTP(S) proxy port, no startup if empty
http_proxy_ip=0.0.0.0
http_proxy_port=80
https_proxy_port=443
https_just_proxy=true
#default https certificate setting
https_default_cert_file=conf/server.pem
https_default_key_file=conf/server.key

##bridge
bridge_type=tcp
bridge_port=8024
bridge_ip=0.0.0.0

# Public password, which clients can use to connect to the server
# After the connection, the server will be able to open relevant ports and parse related domain names according to its own configuration file.
public_vkey=123

#Traffic data persistence interval(minute)
#Ignorance means no persistence
#flow_store_interval=1

# log level LevelEmergency->0  LevelAlert->1 LevelCritical->2 LevelError->3 LevelWarning->4 LevelNotice->5 LevelInformational->6 LevelDebug->7
log_level=7
#log_path=nps.log

#Whether to restrict IP access, true or false or ignore
#ip_limit=true

#p2p
#p2p_ip=127.0.0.1
#p2p_port=6000

#web
web_host=a.o.com
web_username=admin
web_password=123
web_port = 8080
web_ip=0.0.0.0
web_base_url=
web_open_ssl=false
web_cert_file=conf/server.pem
web_key_file=conf/server.key
# if web under proxy use sub path. like http://host/nps need this.
#web_base_url=/nps

#Web API unauthenticated IP address(the len of auth_crypt_key must be 16)
#Remove comments if needed
#auth_key=test
auth_crypt_key =1234567812345678

#allow_ports=9001-9009,10001,11000-12000

#Web management multi-user login
allow_user_login=false
allow_user_register=false
allow_user_change_username=false


#extension
allow_flow_limit=false
allow_rate_limit=false
allow_tunnel_num_limit=false
allow_local_proxy=false
allow_connection_num_limit=false
allow_multi_ip=false
system_info_display=false

#cache
http_cache=false
http_cache_length=100

#get origin ip
http_add_origin_header=false

#pprof debug options
#pprof_ip=0.0.0.0
#pprof_port=9999

#client disconnect timeout
disconnect_timeout=60

它里面参数很多,选取确定一定以及肯定要修改的强调一下,其实这里有一些参数是可以单独开一篇教程讲解,因为参数值的不同会衍生出很多用法和玩法。

注意

如下参数确定一定以及肯定要修改,否则被不怀好意的扫描到你的服务器安装 nps,他靠猜测就进了你的服务器,你的服务器容易暴毙。

参数名含义默认值
appname当前 nps 系统的名称,你可以取一个响亮的名字nps
runmode系统运行模式,如果是用户生产环境记得改成 prodev
web_username系统超级管理员的登录名admin
web_password系统超级管理员密码123
web_port管理员界面登录的接口8080
public_vkey开放的客户端连接密码,也就是说如果有了这个,所有的客户端(不管是不是你的)都可以通过当前服务器把客户端自身暴露在公网上,很危险,强烈建议删除123
auth_crypt_key加密登录的密钥,改成随意的 16 位字符串1234567812345678

按照自己的需求,上面的几个默认值一定要改掉,否则日后一旦你被别人扫描出来你在这台机器上安装了 nps,很容易把你自己的客户端暴露出来,我相信你也不愿意自己家里的电脑所有文件被人拷贝走,成为下一个冠希哥,对吧[doge]

改完之后,重启 nps

$ sudo nps restart

回到当前操作的电脑,打开浏览器输入如下地址

http://1.2.3.4:8080 (请填写你自己机器的公网 IP)

你会看到如下的界面

image.png

这说明你已经成功的安装了服务端,然后输入刚才你修改的 web_usernameweb_password 就可以登录进去

登录进去之后可以看到如下的控制面板(请忽略我屏幕上显示的连接的客户端有一个,因为我截图的网站是我正在使用的内网穿越的服务站点,你第一次打开,上面的客户端和在线客户端应该都是 0):

image.png

服务端的安装和启动就此结束,我们进入客户端环节 -> nps 从零启动 - 2. 客户端 Linux 篇