SFTP 서버가 작동하지 않습니다

SFTP 서버가 작동하지 않습니다

저는 Linux에 대한 경험이 없기 때문에 Ubuntu 18.04 Server에서 SFTP 서버를 설정하는 데 사용한 모든 명령을 여기에 보관하겠습니다.

내 목표는 다음 기준을 충족하는 SFTP 서버를 만드는 것입니다.

  • 모든 SFTP 사용자는 "sftp_users" 그룹에 있습니다.
  • 모든 사용자들원하지 않는다자체 폴더가 있습니다.
  • 모든 사용자가 액세스할 수 있습니다.오직1개의 공용 폴더(/data/sftp)에.
  • 모든 SFTP 사용자는 이 공용 폴더에 있는 모든 파일을 읽고, 쓰고, 실행(업로드, 다운로드, 삭제 등이라고도 함)할 수 있습니다.

서버를 설정하는 데 사용한 명령

apt update
apt install openssh-server
mkdir -p /data/sftp
chmod 701 /data
groupadd sftp_users
useradd -g sftp_users -d /data/sftp -s /sbin/nologin sftptest
passwd sftptest
chown -R root:sftp_users /data/sftp
chown -R sftptest:sftp_users /data/sftp
nano /etc/ssh/sshd_config

파일 끝에 이 줄을 추가하세요.

Match Group sftp_users
ChrootDirectory /data/sftp
ForceCommand internal-sftp

그리고 해냈어

systemctl restart sshd

SFTP를 통해 서버에 연결하려고 하면WinSCP그리고 그것은 나에게 오류를 주었다

Authentication log (see session log for details):
Using username "sftptest".

Authentication failed.

전체 로그:

. 2019-08-10 23:49:45.266 --------------------------------------------------------------------------
. 2019-08-10 23:49:45.266 WinSCP Version 5.15.3 (Build 9730) (OS 10.0.17134 - Windows 10 Enterprise)
. 2019-08-10 23:49:45.267 Configuration: HKCU\Software\Martin Prikryl\WinSCP 2\
. 2019-08-10 23:49:45.267 Log level: Normal
. 2019-08-10 23:49:45.267 Local account: %PCNAME%
. 2019-08-10 23:49:45.267 Working directory: C:\Program Files (x86)\WinSCP
. 2019-08-10 23:49:45.267 Process ID: 5780
. 2019-08-10 23:49:45.267 Command-line: "C:\Program Files (x86)\WinSCP\WinSCP.exe" 
. 2019-08-10 23:49:45.275 Time zone: Current: GMT+3, Standard: GMT+2 (FLE Standard Time), DST: GMT+3 (FLE Daylight Time), DST Start: 31.03.2019, DST End: 27.10.2019
. 2019-08-10 23:49:45.275 Login time: 10 August 2019 y. 23:49:45
. 2019-08-10 23:49:45.275 --------------------------------------------------------------------------
. 2019-08-10 23:49:45.275 Session name: sftptest@%INTERNALIP% (Ad-Hoc site)
. 2019-08-10 23:49:45.275 Host name: %INTERNALIP% (Port: 22)
. 2019-08-10 23:49:45.275 User name: sftptest (Password: Yes, Key file: No, Passphrase: No)
. 2019-08-10 23:49:45.275 Tunnel: No
. 2019-08-10 23:49:45.275 Transfer Protocol: SFTP (SCP)
. 2019-08-10 23:49:45.275 Ping type: Off, Ping interval: 30 sec; Timeout: 15 sec
. 2019-08-10 23:49:45.275 Disable Nagle: No
. 2019-08-10 23:49:45.275 Proxy: None
. 2019-08-10 23:49:45.275 Send buffer: 262144
. 2019-08-10 23:49:45.275 SSH protocol version: 2; Compression: No
. 2019-08-10 23:49:45.275 Bypass authentication: No
. 2019-08-10 23:49:45.275 Try agent: Yes; Agent forwarding: No; TIS/CryptoCard: No; KI: Yes; GSSAPI: Yes
. 2019-08-10 23:49:45.275 GSSAPI: Forwarding: No; Libs: gssapi32,sspi,custom; Custom: 
. 2019-08-10 23:49:45.276 Ciphers: aes,chacha20,blowfish,3des,WARN,arcfour,des; Ssh2DES: No
. 2019-08-10 23:49:45.276 KEX: ecdh,dh-gex-sha1,dh-group14-sha1,rsa,WARN,dh-group1-sha1
. 2019-08-10 23:49:45.276 SSH Bugs: Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto
. 2019-08-10 23:49:45.276 Simple channel: Yes
. 2019-08-10 23:49:45.276 Return code variable: Autodetect; Lookup user groups: Auto
. 2019-08-10 23:49:45.276 Shell: default
. 2019-08-10 23:49:45.276 EOL: LF, UTF: Auto
. 2019-08-10 23:49:45.276 Clear aliases: Yes, Unset nat.vars: Yes, Resolve symlinks: Yes; Follow directory symlinks: No
. 2019-08-10 23:49:45.276 LS: ls -la, Ign LS warn: Yes, Scp1 Comp: No; Exit code 1 is error: No
. 2019-08-10 23:49:45.276 SFTP Bugs: Auto,Auto
. 2019-08-10 23:49:45.276 SFTP Server: default
. 2019-08-10 23:49:45.276 Local directory: default, Remote directory: home, Update: Yes, Cache: Yes
. 2019-08-10 23:49:45.276 Cache directory changes: Yes, Permanent: Yes
. 2019-08-10 23:49:45.276 Recycle bin: Delete to: No, Overwritten to: No, Bin path: 
. 2019-08-10 23:49:45.276 DST mode: Unix
. 2019-08-10 23:49:45.276 --------------------------------------------------------------------------
. 2019-08-10 23:49:45.317 Looking up host "%INTERNALIP%" for SSH connection
. 2019-08-10 23:49:45.317 Connecting to %INTERNALIP% port 22
. 2019-08-10 23:49:45.349 We claim version: SSH-2.0-WinSCP_release_5.15.3
. 2019-08-10 23:49:45.380 Server version: SSH-2.0-OpenSSH_7.6p1 Ubuntu-4ubuntu0.3
. 2019-08-10 23:49:45.380 Using SSH protocol version 2
. 2019-08-10 23:49:45.381 Doing ECDH key exchange with curve Curve25519 and hash SHA-256
. 2019-08-10 23:49:45.784 Server also has ecdsa-sha2-nistp256/ssh-rsa host keys, but we don't know any of them
. 2019-08-10 23:49:45.785 Host key fingerprint is:
. 2019-08-10 23:49:45.785 ssh-ed25519 256 %FINGERPRINT% %KEY%
. 2019-08-10 23:49:45.816 Asking user:
. 2019-08-10 23:49:45.816 **Continue connecting to an unknown server and add its host key to a cache?**
. 2019-08-10 23:49:45.816 
. 2019-08-10 23:49:45.816 The server's host key was not found in the cache. You have no guarantee that the server is the computer you think it is.
. 2019-08-10 23:49:45.816 
. 2019-08-10 23:49:45.816 The server's Ed25519 key details are:
. 2019-08-10 23:49:45.816 
. 2019-08-10 23:49:45.816     Algorithm:    ssh-ed25519 256
. 2019-08-10 23:49:45.816     SHA-256:  %KEY%
. 2019-08-10 23:49:45.816     MD5:  %FINGERPRINT%
. 2019-08-10 23:49:45.816 
. 2019-08-10 23:49:45.816 If you trust this host, press Yes. To connect without adding host key to the cache, press No. To abandon the connection press Cancel. ()
. 2019-08-10 23:49:47.215 Initialised AES-256 SDCTR client->server encryption
. 2019-08-10 23:49:47.215 Initialised HMAC-SHA-256 client->server MAC algorithm
. 2019-08-10 23:49:47.215 Initialised AES-256 SDCTR server->client encryption
. 2019-08-10 23:49:47.215 Initialised HMAC-SHA-256 server->client MAC algorithm
! 2019-08-10 23:49:47.259 Using username "sftptest".
. 2019-08-10 23:49:47.291 Server offered these authentication methods: publickey,password
. 2019-08-10 23:49:47.291 Prompt (password, "SSH password", <no instructions>, "&Password: ")
. 2019-08-10 23:49:47.291 Using stored password.
. 2019-08-10 23:49:47.297 Sent password
. 2019-08-10 23:49:47.310 Access granted
. 2019-08-10 23:49:47.310 Opening session as main channel
. 2019-08-10 23:49:48.472 Network error: Software caused connection abort
* 2019-08-10 23:49:48.549 (EFatal) Network error: Software caused connection abort
* 2019-08-10 23:49:48.550 Authentication log (see session log for details):
* 2019-08-10 23:49:48.550 Using username "sftptest".
* 2019-08-10 23:49:48.550 
* 2019-08-10 23:49:48.550 Authentication failed.

답변1

네, 댓글에 있는 제안이 제게 많은 도움이 되었습니다. 트릭이 다음 명령을 실행했습니다.

chown root /data
chmod go-w /data
chown sftptest:sftp_users /data/sftp
chmod ug+rwX /data/sftp
chmod 755 /data

또한 편집되었습니다 sshd_config. 변경됨

ChrootDirectory /data/sftp

그리고

ChrootDirectory /data

관련 정보