sshserv

所属分类:Telnet服务器
开发工具:GO
文件大小:0KB
下载次数:0
上传日期:2021-10-28 01:36:19
上 传 者sh-1993
说明:  SSH服务器使用golang实现,
(A SSH Server implements with golang,)

文件列表:
LICENSE (35149, 2021-10-27)
api/ (0, 2021-10-27)
api/api.go (2182, 2021-10-27)
api/api_test.go (24524, 2021-10-27)
api/api_utils.go (10054, 2021-10-27)
api/internal_test.go (6320, 2021-10-27)
api/quota.go (1326, 2021-10-27)
api/router.go (2405, 2021-10-27)
api/schema/ (0, 2021-10-27)
api/schema/openapi.yaml (20812, 2021-10-27)
api/user.go (4257, 2021-10-27)
change.md (36, 2021-10-27)
cli/ (0, 2021-10-27)
cli/bolt.go (944, 2021-10-27)
cli/kubecp.go (9153, 2021-10-27)
cli/makefile (77, 2021-10-27)
cli/runcmd (1626112, 2021-10-27)
cli/runcmd.go (1888, 2021-10-27)
cli/runcmd.py (203, 2021-10-27)
cli/sftpcli.go (17847, 2021-10-27)
cli/sftpcli_test.go (2635, 2021-10-27)
cli/stderr (540, 2021-10-27)
cli/stdout (250, 2021-10-27)
cli/xx1.txt (1403, 2021-10-27)
cmd/ (0, 2021-10-27)
cmd/root.go (748, 2021-10-27)
cmd/serve.go (8371, 2021-10-27)
config/ (0, 2021-10-27)
config/config.go (4457, 2021-10-27)
config/config_linux.go (225, 2021-10-27)
config/config_nolinux.go (76, 2021-10-27)
config/config_test.go (2860, 2021-10-27)
dataprovider/ (0, 2021-10-27)
dataprovider/bolt.go (7907, 2021-10-27)
dataprovider/dataprovider.go (14670, 2021-10-27)
dataprovider/memory.go_ (10288, 2021-10-27)
dataprovider/mysql.go (2877, 2021-10-27)
dataprovider/pgsql.go (2832, 2021-10-27)
dataprovider/sqlcommon.go (7069, 2021-10-27)
... ...

# SSHServ [![Build Status](https://travis-ci.org/drakkan/sftpgo.svg?branch=master)](https://travis-ci.org/drakkan/sftpgo) [![Code Coverage](https://codecov.io/gh/drakkan/sftpgo/branch/master/graph/badge.svg)](https://codecov.io/gh/drakkan/sftpgo/branch/master) [![Go Report Card](https://goreportcard.com/badge/github.com/drakkan/sftpgo)](https://goreportcard.com/report/github.com/drakkan/sftpgo) [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) [![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go) Full featured and highly configurable SSH server. Based on sftpgo ## Features - Each account is chrooted to his Home Dir. - SFTP accounts are virtual accounts stored in a "data provider". - SQLite, MySQL, PostgreSQL and bbolt (key/value store in pure Go) data providers are supported. - Public key and password authentication. Multiple public keys per user are supported. - Quota support: accounts can have individual quota expressed as max total size and/or max number of files. - Bandwidth throttling is supported, with distinct settings for upload and download. - Per user maximum concurrent sessions. - Per user permissions: list directories content, upload, download, delete, rename, create directories, create symlinks can be enabled or disabled. - Per user files/folders ownership: you can map all the users to the system account that runs SFTPGo (all platforms are supported) or you can run SFTPGo as root user and map each user or group of users to a different system account (*NIX only). - Configurable custom commands and/or HTTP notifications on upload, download, delete or rename. - Automatically terminating idle connections. - Atomic uploads are configurable. - Optional SCP support. - REST API for users and quota management and real time reports for the active connections with possibility of forcibly closing a connection. - Configuration is a your choice: JSON, TOML, YAML, HCL, envfile are supported. - Log files are accurate and they are saved in the easily parsable JSON format. - Local port forwarding - Remote port forwarding - Shell, linux and windows - HDFS filesystem support, based on https://github.com/colinmarc/hdfs ## compile - Linux go build -ldflags="-s -w" - Compile for Windows on Linux GOOS=windows GOARCH=amd64 go build (Do not use sqlite Provider, use bolt instead.) ## 使用方法样例 基于sqlite3保存登录信息 ./sftpgo serve - 创建密码用户: ```shell script python sftpgo_api_cli.py add-user myuser --password "test_pwd" --home-dir="/tmp" --permissions "list" "download" "upload" "delete" "rename" "create_dirs" ``` - 创建pubkey用户: 生成key文件 ssh-keygen -t rsa -b 2048 /home/guanyf/dev/sftpgo/dist/id_rsa ```shell script python sftpgo_api_cli.py add-user keyuser --public-keys "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC6GC0pJtvEuPmq/SDwMrUaQ2j9Ts80zuGRzqkpgey7UFTmudQKI5tD8pM1xk/Q+JsR3wY+1LsYxhfYHnZkNSVNnT+mYK8aSXOoJxfw8hCg3ZUwm0w8X0PthsTGwnn8Mdcr46B4BAag8SbivYj1JZU8OP84naAlLKB+t3UmPlih6d+9C2TNMxprv6ZDeiX+6dlbXaXXd0vupvi1lBIJ4wbYyce/4Qb89SLDmcBwAsZ0/AnNE8Srv5Q52woWxZpWNkObWmiQF+dFoCp6hw4x1PqqDq6oDw6ob1NhjB+b9bh17VKsMxuyv9mmpCqA1aHSZK+eHRO8lSRmKVkQrd/2ptJD" \ --home-dir="/tmp" \ --permissions "list" "download" "upload" "delete" "rename" "create_dirs" ``` - 测试客户端 ```shell script ssh -N -p 2022 -i ./id_rsa -L 1293:172.18.231.68:1293 keyuser@localhost curl http://localhost:1293 ssh -N -p 2022 -i ./id_rsa -R 8181:172.18.231.68:1293 keyuser@localhost curl http://localhost:8181 ssh-keygen -f "/home/guanyf/.ssh/known_hosts" -R "[localhost]:2022" sftp -P 2022 -i ./id_rsa keyuser@localhost scp -P 2022 -i ./id_rsa keyuser@localhost:/sftpgo.log /tmp/xx scp -P 2022 -i ./id_rsa /tmp/xx keyuser@localhost:/xx1 ``` ## Platforms SFTPGo is developed and tested on Linux. After each commit the code is automatically built and tested on Linux and macOS using Travis CI. Regularly the test cases are manually executed and pass on Windows. Other UNIX variants such as *BSD should work too. ## Requirements - Go 1.12 or higher. - A suitable SQL server or key/value store to use as data provider: PostreSQL 9.4+ or MySQL 5.6+ or SQLite 3.x or bbolt 1.3.x ## Installation Simple install the package to your [$GOPATH](https://github.com/golang/go/wiki/GOPATH "GOPATH") with the [go tool](https://golang.org/cmd/go/ "go command") from shell: ```bash $ go get -u github.com/drakkan/sftpgo ``` Make sure [Git is installed](https://git-scm.com/downloads) on your machine and in your system's `PATH`. SFTPGo depends on [go-sqlite3](https://github.com/mattn/go-sqlite3) that is a CGO package and so it requires a `C` compiler at build time. On Linux and macOS a compiler is easy to install or already installed, on Windows you need to download [MinGW-w64](https://sourceforge.net/projects/mingw-w64/files/) and build SFTPGo from its command prompt. The compiler is a build time only dependency, it is not not required at runtime. If you don't need SQLite, you can also get/build SFTPGo setting the environment variable `GCO_ENABLED` to 0, this way SQLite support will be disabled but PostgreSQL, MySQL and bbolt will work and you don't need a `C` compiler for building. Version info, such as git commit and build date, can be embedded setting the following string variables at build time: - `github.com/drakkan/sftpgo/utils.commit` - `github.com/drakkan/sftpgo/utils.date` For example you can build using the following command: ```bash go build -i -ldflags "-s -w -X github.com/drakkan/sftpgo/utils.commit=`git describe --tags --always --dirty` -X github.com/drakkan/sftpgo/utils.date=`date -u +%FT%TZ`" -o sftpgo ``` and you will get a version that includes git commit and build date like this one: ```bash sftpgo -v SFTPGo version: 0.9.0-dev-90607d4-dirty-2019-08-08T19:28:36Z ``` For Linux, a systemd sample [service](https://github.com/drakkan/sftpgo/tree/master/init/sftpgo.service "systemd service") can be found inside the source tree. Alternately you can use distro packages: - Arch Linux PKGBUILD is available on [AUR](https://aur.archlinux.org/packages/sftpgo-git/ "SFTPGo") ## Configuration The `sftpgo` executable can be used this way: ```bash Usage: sftpgo [command] Available Commands: help Help about any command serv Start the SFTP Server Flags: -h, --help help for sftpgo -v, --version ``` The `serve` subcommand supports the following flags: - `--config-dir` string. Location of the config dir. This directory should contain the `sftpgo` configuration file and is used as the base for files with a relative path (eg. the private keys for the SFTP server, the SQLite or bblot database if you use SQLite or bbolt as data provider). The default value is "." or the value of `SFTPGO_CONFIG_DIR` environment variable. - `--config-file` string. Name of the configuration file. It must be the name of a file stored in config-dir not the absolute path to the configuration file. The specified file name must have no extension we automatically load JSON, YAML, TOML, HCL and Java properties. The default value is "sftpgo" (and therefore `sftpgo.json`, `sftpgo.yaml` and so on are searched) or the value of `SFTPGO_CONFIG_FILE` environment variable. - `--log-compress` boolean. Determine if the rotated log files should be compressed using gzip. Default `false` or the value of `SFTPGO_LOG_COMPRESS` environment variable (1 or `true`, 0 or `false`). - `--log-file-path` string. Location for the log file, default "sftpgo.log" or the value of `SFTPGO_LOG_FILE_PATH` environment variable. - `--log-max-age` int. Maximum number of days to retain old log files. Default 28 or the value of `SFTPGO_LOG_MAX_AGE` environment variable. - `--log-max-backups` int. Maximum number of old log files to retain. Default 5 or the value of `SFTPGO_LOG_MAX_BACKUPS` environment variable. - `--log-max-size` int. Maximum size in megabytes of the log file before it gets rotated. Default 10 or the value of `SFTPGO_LOG_MAX_SIZE` environment variable. - `--log-verbose` boolean. Enable verbose logs. Default `true` or the value of `SFTPGO_LOG_VERBOSE` environment variable (1 or `true`, 0 or `false`). If you don't configure any private host keys, the daemon will use `id_rsa` in the configuration directory. If that file doesn't exist, the daemon will attempt to autogenerate it (if the user that executes SFTPGo has write access to the config-dir). The server supports any private key format supported by [`crypto/ssh`](https://github.com/golang/crypto/blob/master/ssh/keys.go#L32). Before starting `sftpgo` a dataprovider must be configured. Sample SQL scripts to create the required database structure can be found inside the source tree [sql](https://github.com/drakkan/sftpgo/tree/master/sql "sql") directory. The SQL scripts filename's is, by convention, the date as `YYYYMMDD` and the suffix `.sql`. You need to apply all the SQL scripts for your database ordered by name, for example `20190706.sql` must be applied before `20190728.sql` and so on. The `sftpgo` configuration file contains the following sections: - **"sftpd"**, the configuration for the SFTP server - `bind_port`, integer. The port used for serving SFTP requests. Default: 2022 - `bind_address`, string. Leave blank to listen on all available network interfaces. Default: "" - `idle_timeout`, integer. Time in minutes after which an idle client will be disconnected. Default: 15 - `max_auth_tries` integer. Maximum number of authentication attempts permitted per connection. If set to a negative number, the number of attempts are unlimited. If set to zero, the number of attempts are limited to 6. - `umask`, string. Umask for the new files and directories. This setting has no effect on Windows. Default: "0022" - `banner`, string. Identification string used by the server. Default "SFTPGo" - `upload_mode` integer. 0 means standard, the files are uploaded directly to the requested path. 1 means atomic: files are uploaded to a temporary path and renamed to the requested path when the client ends the upload. Atomic mode avoids problems such as a web server that serves partial files when the files are being uploaded - `actions`, struct. It contains the command to execute and/or the HTTP URL to notify and the trigger conditions - `execute_on`, list of strings. Valid values are `download`, `upload`, `delete`, `rename`. On folder deletion a `delete` notification will be sent for each deleted file. Leave empty to disable actions. - `command`, string. Absolute path to the command to execute. Leave empty to disable. The command is invoked with the following arguments: - `action`, any valid `execute_on` string - `username`, user who did the action - `path` to the affected file. For `rename` action this is the old file name - `target_path`, non empty for `rename` action, this is the new file name - `http_notification_url`, a valid URL. An HTTP GET request will be executed to this URL. Leave empty to disable. The query string will contain the following parameters that have the same meaning of the command's arguments: - `action` - `username` - `path` - `target_path`, added for `rename` action only - `keys`, struct array. It contains the daemon's private keys. If empty or missing the daemon will search or try to generate `id_rsa` in the configuration directory. - `private_key`, path to the private key file. It can be a path relative to the config dir or an absolute one. - `enable_scp`, boolean. Default disabled. Set to `true` to enable SCP support. SCP is an experimental feature, we have our own SCP implementation since we can't rely on `scp` system command to proper handle permissions, quota and user's home dir restrictions. The SCP protocol is quite simple but there is no official docs about it, so we need more testing and feedbacks before enabling it by default. We may not handle some borderline cases or have sneaky bugs. Please do accurate tests yourself before enabling SCP and let us known if something does not work as expected for your use cases. SCP between two remote hosts is supported using the `-3` scp option. - **"data_provider"**, the configuration for the data provider - `driver`, string. Supported drivers are `sqlite`, `mysql`, `postgresql`, `bolt` - `name`, string. Database name. For driver `sqlite` this can be the database name relative to the config dir or the absolute path to the SQLite database. - `host`, string. Database host. Leave empty for driver `sqlite` and `bolt` - `port`, integer. Database port. Leave empty for driver `sqlite` and `bolt` - `username`, string. Database user. Leave empty for driver `sqlite` and `bolt` - `password`, string. Database password. Leave empty for driver `sqlite` and `bolt` - `sslmode`, integer. Used for drivers `mysql` and `postgresql`. 0 disable SSL/TLS connections, 1 require ssl, 2 set ssl mode to `verify-ca` for driver `postgresql` and `skip-verify` for driver `mysql`, 3 set ssl mode to `verify-full` for driver `postgresql` and `preferred` for driver `mysql` - `connectionstring`, string. Provide a custom database connection string. If not empty this connection string will be used instead of build one using the previous parameters. Leave empty for driver `bolt` - `users_table`, string. Database table for SFTP users - `manage_users`, integer. Set to 0 to disable users management, 1 to enable - `track_quota`, integer. Set the preferred way to track users quota between the following choices: - 0, disable quota tracking. REST API to scan user dir and update quota will do nothing - 1, quota is updated each time a user upload or delete a file even if the user has no quota restrictions - 2, quota is updated each time a user upload or delete a file but only for users with quota restrictions. With this configuration the "quota scan" REST API can still be used to periodically update space usage for users without quota restrictions - **"httpd"**, the configuration for the HTTP server used to serve REST API - `bind_port`, integer. The port used for serving HTTP requests. Set to 0 to disable HTTP server. Default: 8080 - `bind_address`, string. Leave blank to listen on all available network interfaces. Default: "127.0.0.1" Here is a full example showing the default config in JSON format: ```json { "sftpd": { "bind_port": 2022, "bind_address": "", "idle_timeout": 15, "max_auth_tries": 0, "umask": "0022", "banner": "SFTPGo", "actions": { "execute_on": [], "command": "", "http_notification_url": "" }, "keys": [], "enable_scp": false }, "data_provider": { "driver": "sqlite", "name": "sftpgo.db", "host": "", "port": 5432, "username": "", "password": "", "sslmode": 0, "connection_string": "", "users_table": "users", "manage_users": 1, "track_quota": 2 }, "httpd": { "bind_port": 8080, "bind_address": "127.0.0.1" } } ``` If you want to use a private key that use an algorithm different from RSA or more than one private key then replace the empty `keys` array with something like this: ```json {"keys": [ { "private_key": "id_rsa" }, { "private_key": "id_ecdsa" } ]} ``` The configuration can be read from JSON, TOML, YAML, HCL, envfile and Java properties config files, if your `config-file` flag is set to `sftpgo` (default value) you need to create a configuration file called `sftpgo.json` or `sftpgo.yaml` and so on inside `config-dir`. You can also configure all the available options using environment variables, sftpgo will check for environment variables with a name matching the key uppercased and prefixed with the `SFTPGO_`. You need to use `__` to traverse a struct. Let's see some examples: - To set sftpd `bind_port` you need to define the env var `SFTPGO_SFTPD__BIND_PORT` - To set the `execute_on` actions you need to define the env var `SFTPGO_SFTPD__ACTIONS__EXECUTE_ON` for example `SFTPGO_SFTPD__ACTIONS__EXECUTE_ON=upload,download` To start the SFTP Server with the default values for the command line flags simply use: ```bash sftpgo serv ``` ## Account's configuration properties For each account the following properties can be configured: - `username` - `password` used for password authentication. For users created using SFTPGo REST API if the password has no known hashing algo prefix it will be stored using argon2id. SFTPGo supports checking passwords stored with bcrypt and pbkdf2 too. For pbkdf2 the supported format is `$$$$`, where algo is `pbkdf2-sha1` or `pbkdf2-sha256` or `pbkdf2-sha512`. For example the `pbkdf2-sha256` of the word `password` using 150000 iterations and `E86a9YMX3zC7` as salt must be stored as `$pbkdf2-sha256$150000$E86a9YMX3zC7$R5J62hsSq+pYw00hLLPKBbcGXmq7fj5+/M0IFoYtZbo=`. For bcrypt the format must be the one supported by golang's [crypto/bcrypt](https://godoc.org/golang.org/x/crypto/bcrypt) package, for example the password `secret` with cost `14` must be stored as `$2a$14$ajq8Q7fbtFRQvXpdCq7Jcuy.Rx1h/L4J60Otx.gyNLbAYctGMJ9tK`. Using the REST API you can send a password hashed as bcrypt or pbkdf2 and it will be stored as is. - `public_keys` array of public keys. At least one public key or the password is mandatory. - `home_dir` The user cannot upload or download files outside this directory. Must be an absolute path - `uid`, `gid`. If sftpgo runs as root system user then the created files and directories will be assigned to this system uid/gid. Ignored on windows and if sftpgo runs as non root user: in this case files and directories for all SFTP users will be owned by the system user that runs sftpgo. - `max_sessions` maximum concurrent sessions. 0 means unlimited - `quota_size` maximum size allowed as bytes. 0 means unlimited - `quota_files` maximum number of files allowed. 0 means unlimited - `permissions` the following permissions are supported: - `*` all permission are granted - `list` list items is allowed - `download` download files is allowed - `upload` upload files is allowed - `delete` delete files or directories is allowed - `rename` rename files or directories is allowed - `create_dirs` create directories is allowed - `create_symlinks` create symbolic links is allowed - `upload_bandwidth` maximum upload bandwidth as KB/s, 0 means unlimited - `download_bandwidth` maximum download bandwidth as KB/s, 0 means unlimited These properties are stored inside the data provider. If you want to use your existing accounts, you can create a database view. Since a view is read only, you have to disable user management and quota tracking so SFTPGo will never try to write to the view. ## REST API SFTPGo exposes REST API to manage users and quota and to get real time reports for the active connections with possibility of forcibly closing a connection. If quota tracking is enabled in `sftpgo` configuration file, then the used size and number of files are updated each time a file is added/removed. If files are added/removed not using SFTP or if you change `track_quota` from `2` to `1`, you can rescan the user home dir and update the used quota using the REST API. REST API is designed to run on localhost or on a trusted network, if you need HTTPS or authentication you can setup a reverse proxy using an HTTP Server such as Apache or NGNIX. For example you can keep SFTPGo listening on ... ...

近期下载者

相关文件


收藏者