Git Product home page Git Product logo

sftpserver's Introduction

sftpserver

SFTP Server (SSH File Transfer Protocol) based on Apache MINA SSHD. Open Source Java project under Apache License v2.0

Current Stable Version is 1.4.0


Versions

sftpserver Java
1.0.x 1.6+
1.1.x 1.6+
1.2.x 1.7+
1.3.x 1.8+
1.4.x 1.8+

Config:

${sftp.home}/conf/[id]/sftpd.properties (all in one file)
#
## Global Options
#
# Listen on localhost and localnet
#sftpserver.global.host=127.0.0.1,192.168.1.1
# Listen on TCP port 22222
sftpserver.global.port=22222
# Enable compression (requires jzlib) (default: false)
sftpserver.global.compress=true
# Enable dummy shell (default: false)
sftpserver.global.dummyshell=true
# Enable log request (default: false)
sftpserver.global.logrequest=true
#
## Configure user "test"
#
# Password for user (unencrypted-plain-text)
#sftpserver.user.test.userpassword=changeit
# Password for user (encrypted)
sftpserver.user.test.userpassword=$1$156RlTZJ$76bzjtXvDfgvouurtgEI10
# PublicKeys for user (OpenSSH format)
sftpserver.user.test.userkey.1=ssh-rsa AAAAB3NzaC1yc2EAAAADA...E7uQ==
sftpserver.user.test.userkey.2=ssh-ed25519 AAAAC3NzaC1...QfX
sftpserver.user.test.userkey.3=ecdsa-sha2-nistp256 AAAAE2VjZ...Z99xM=
# Set user home directory (chrooted)
sftpserver.user.test.homedirectory=./home/test/
# Enable user (default: false)
sftpserver.user.test.enableflag=true
# Enable write (default: false)
sftpserver.user.test.writepermission=true
#
${sftp.home}/conf/[id]/sftpd.properties + ${sftp.home}/conf/[id]/htpasswd
#
## Global Options
#
# Listen on TCP port 22222
sftpserver.global.port=22222
# Enable compression (requires jzlib) (default: false)
sftpserver.global.compress=true
# Enable dummy shell (default: false)
sftpserver.global.dummyshell=true
#
## Configure htpasswd
#
# Enable htpasswd (default: false)
sftpserver.htpasswd.enableflag=true
# Set home directory for all users (chrooted)
sftpserver.htpasswd.homedirectory=./home/test/
# Enable write (default: false)
sftpserver.htpasswd.writepermission=true
#

Running (Linux)

./bin/sftpd.sh <run|start|stop|restart|status> [id]

Upstart Script (Linux)

./bin/sftpd.conf (you can copy to /etc/init/)

Systemd Service (Linux)

./bin/sftpd.service (you can copy to /etc/systemd/system/)

Generate Encrypted Password (Linux)

./bin/sftpd.sh <pwd>

DONEs

  • Use Java SecurityManager/Policy File
  • Non operating system accounts
  • Homes are chrooted
  • ReadOnly accounts
  • Encrypted Passwords (SHA2/MD5/APR1)
  • PublicKey Authenticator (OpenSSH keys RSA/EcDSA/Ed25519)
  • Support htpasswd file (APR1)

MISC

Current hardcoded values:

  • Hostkeys are writed to: hostkey.pem or hostkey.ser in ${sftp.home}/keys/ directory
  • SecurityManager/Policy File is in conf/${ID}/sftpd.policy (custom) or lib/sftpd.policy (generic)
  • Htpasswd File is in conf/${ID}/htpasswd (custom) or conf/htpasswd (generic)
  • Default KexAlgorithms: diffie-hellman-group14-sha256, diffie-hellman-group16-sha512, diffie-hellman-group-exchange-sha256, ecdh-sha2-nistp256, ecdh-sha2-nistp384, ecdh-sha2-nistp521, diffie-hellman-group14-sha1
  • Default Ciphers: aes128-ctr, aes192-ctr, aes256-ctr
  • Default MACs: [email protected], [email protected], [email protected], hmac-sha2-256, hmac-sha2-512, hmac-sha1

Maven Dependencies:

Apache MINA SSHD CHANGELOG

  • mina-core-XXX.jar
  • sshd-core-XXX.jar
  • sshd-sftp-XXX.jar
  • sshd-scp-XXX.jar

Apache Commons Codec (password encryption)

  • commons-codec-XXX.jar

Log4J/Reload4J (logging)

  • reload4j-XXX.jar

SLF4J (logging)

  • slf4j-api-XXX.jar
  • slf4j-reload4j-XXX.jar

Bouncy Castle (encryption)

  • bcprov-jdk15on-XXX.jar
  • bcpkix-jdk15on-XXX.jar

JZlib (for compression)

  • jzlib-XXX.jar

Inspired in mina-sshd and openssh.

sftpserver's People

Contributors

ggrandes avatar landro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sftpserver's Issues

Log: Ignore null connections (fast connect/close)

The typical ELB health-checks:

2023-05-15 18:27:48,047 INFO org.javastack.sftpserver.ServiceLogger session created(@10.x.x.xx:37118)
2023-05-15 18:27:48,047 INFO org.javastack.sftpserver.ServiceLogger session closed(@10.x.x.xx:37118)
2023-05-15 18:27:48,063 INFO org.javastack.sftpserver.ServiceLogger session created(@10.x.x.xx:37114)
2023-05-15 18:27:48,063 INFO org.javastack.sftpserver.ServiceLogger session closed(@10.x.x.xx:37114)
2023-05-15 18:27:48,548 INFO org.javastack.sftpserver.ServiceLogger session created(@10.x.x.xx:9088)
2023-05-15 18:27:48,548 INFO org.javastack.sftpserver.ServiceLogger session closed(@10.x.x.xx:9088)
...and many many more

Error: Could not find or load main class org.javastack.sftpserver.Server

I just downloaded zip archive and expanded in my work folder. Tried to run sftp server sample config on Linux Mint 20 and I am getting error. Any Ideas what may be the problem?

~/work/sftpserver$ sudo ./bin/sftpd.sh run sampleconf
./bin/sftpd.sh: line 24: cd: /opt/sftpd: No such file or directory
[0.003s][warning][gc] -XX:+PrintGCDetails is deprecated. Will use -Xlog:gc* instead.
-XX:G1ConcRefinementThreads=2 -XX:GCDrainStackTargetSize=64 -XX:InitialHeapSize=64220672 -XX:MaxHeapSize=67108864 -XX:+PrintCommandLineFlags -XX:-PrintFlagsFinal -XX:+PrintGCDetails -XX:ReservedCodeCacheSize=251658240 -XX:+SegmentedCodeCache -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseG1GC
[0.007s][info ][gc,heap] Heap region size: 1M
[0.008s][info ][gc ] Using G1
[0.008s][info ][gc,heap,coops] Heap address: 0x00000000fc000000, size: 64 MB, Compressed Oops mode: 32-bit
[0.009s][info ][gc,cds ] Mark closed archive regions in map: [0x00000000fff00000, 0x00000000fff6aff8]
[0.009s][info ][gc,cds ] Mark open archive regions in map: [0x00000000ffe00000, 0x00000000ffe46ff8]
openjdk version "11.0.19" 2023-04-18
OpenJDK Runtime Environment (build 11.0.19+7-post-Ubuntu-0ubuntu120.04.1)
OpenJDK 64-Bit Server VM (build 11.0.19+7-post-Ubuntu-0ubuntu120.04.1, mixed mode, sharing)
Error: Could not find or load main class org.javastack.sftpserver.Server
Caused by: java.lang.ClassNotFoundException: org.javastack.sftpserver.Server
[0,074s][info ][gc,heap,exit ] Heap
[0,074s][info ][gc,heap,exit ] garbage-first heap total 65536K, used 712K [0x00000000fc000000, 0x0000000100000000)
[0,074s][info ][gc,heap,exit ] region size 1024K, 1 young (1024K), 0 survivors (0K)
[0,074s][info ][gc,heap,exit ] Metaspace used 462K, capacity 4539K, committed 4864K, reserved 1056768K
[0,074s][info ][gc,heap,exit ] class space used 45K, capacity 405K, committed 512K, reserved 1048576K

Default server does not start due to policy problem

Starting the default server with default config aborts the server with this error:

2017-10-17 18:59:02,061 INFO org.javastack.sftpserver.Server Starting
2017-10-17 18:59:02,062 INFO org.javastack.sftpserver.Server Config file loaded 6 lines
2017-10-17 18:59:02,269 INFO org.apache.sshd.common.util.SecurityUtils Trying to register BouncyCastle as a JCE provider
2017-10-17 18:59:02,391 INFO org.apache.sshd.common.util.SecurityUtils Registration succeeded
2017-10-17 18:59:02,434 INFO org.javastack.sftpserver.Server SSHD SSHD-CORE-1.2.0
2017-10-17 18:59:02,447 INFO org.javastack.sftpserver.Server Listen on port=22222
2017-10-17 18:59:02,454 ERROR org.javastack.sftpserver.Server Exception java.security.AccessControlException: access denied ("java.util.PropertyPermission" "*" "read,write")
java.security.AccessControlException: access denied ("java.util.PropertyPermission" "*" "read,write")
        at java.security.AccessControlContext.checkPermission(AccessControlContext.java:472)
        at java.security.AccessController.checkPermission(AccessController.java:884)
        at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
        at java.lang.SecurityManager.checkPropertiesAccess(SecurityManager.java:1262)
        at java.lang.System.getProperties(System.java:630)
        at org.apache.sshd.common.SyspropsMapWrapper.keySet(SyspropsMapWrapper.java:137)
        at org.apache.sshd.common.SyspropsMapWrapper.isEmpty(SyspropsMapWrapper.java:132)
        at org.apache.sshd.common.util.GenericUtils.isEmpty(GenericUtils.java:233)
        at org.apache.sshd.common.PropertyResolverUtils.resolvePropertyValue(PropertyResolverUtils.java:315)
        at org.apache.sshd.common.PropertyResolverUtils.getIntProperty(PropertyResolverUtils.java:148)
        at org.apache.sshd.common.io.AbstractIoServiceFactory.getNioWorkers(AbstractIoServiceFactory.java:84)
        at org.apache.sshd.common.io.nio2.Nio2ServiceFactory.<init>(Nio2ServiceFactory.java:42)
        at org.apache.sshd.common.io.nio2.Nio2ServiceFactoryFactory.create(Nio2ServiceFactoryFactory.java:54)
        at org.apache.sshd.common.io.DefaultIoServiceFactoryFactory.create(DefaultIoServiceFactoryFactory.java:49)
        at org.apache.sshd.common.helpers.AbstractFactoryManager.getIoServiceFactory(AbstractFactoryManager.java:101)
        at org.apache.sshd.server.SshServer.createAcceptor(SshServer.java:401)
        at org.apache.sshd.server.SshServer.start(SshServer.java:301)
        at org.javastack.sftpserver.Server.start(Server.java:245)
        at org.javastack.sftpserver.Server.main(Server.java:89)

Adding this line to lib/sftpd.policy solves the problem
permission java.util.PropertyPermission "*", "read,write";

Server'host key did not match the signature supplied.

Hi Mr Grandes,
I was trying to use you sftp server in my personal project, when I try to login the server via Winscp I got server's host key did not match the signature supplied warning. Do you by any chance know what happens? Any suggestions are appreciated.

Generate hostkey with shh-rsa instead of ssh-dss

Currently the default implementation generates a host key with ssh-dss key type.
Most ssh clients don't any longer support the ssh-dss type, better would be to generate the server key with a ssh-rsa or better key.

There the corresponding log entry when trying to connect with open ssh client 7.4 distributed with Debian 9

2017-10-17 18:38:29,707 WARN org.apache.sshd.server.session.ServerSessionImpl exceptionCaught(ServerSessionImpl[null@/0:0:0:0:0:0:0:1:56314])[state=Opened] IllegalStateException: Unable to negotiate key exc
hange for server host key algorithms (client: [email protected],[email protected],[email protected],[email protected],ssh-
[email protected],ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-ed25519,rsa-sha2-512,rsa-sha2-256,ssh-rsa / server: ssh-dss)

Here the openssh page mentioning this:
[https://www.openssh.com/legacy.html]

OpenSSH 7.0 and greater similarly disable the ssh-dss (DSA) public key algorithm. It too is weak and we recommend against its use.

download file, it have a EOF Exception

download file, it have a EOF Exception . it run in windows 7 environment, jdk 1.8 .

Server$CustomSftpSubsystemFactory$1:3292 - doSendStatus(ServerSessionImpl[test@/127.0.0.1:55462])[id=383] SSH_FXP_STATUS (substatus=SSH_FX_EOF, lang=, msg=java.io.EOFException: Unable to read 16384 bytes from offset=12340403 of 7b6d575567751ee2088f69f846ae28e6)

How to get started tutorial..?

Hi,

I downloaded the latest release and played around with sftpd.sh start or pwd. I don't manage to get it running. Somethings is not right. I seems to look for files in /opt/sftpd/... and then fails.

Maybe there is a step-by-step guide showing how it is done?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.