ubuntuusers.de

sftd

Status: Gelöst | Ubuntu-Version: Server 25.04 (Plucky Puffin)
Antworten |

DerTom246

Anmeldungsdatum:
16. Januar 2021

Beiträge: 8

Hallo zusammen,

ich verzweifele gerade an der Einrichtung eines sftp-servers unter Ubuntu. Falls jemand wissen möchte, warum 25.04... weil 24.10 den x553 intel nic nicht unterstützt. Im Anhang habe ich die Ausgabe aus einer Win-Maschine heraus dokumentiert.

https://media-cdn.ubuntu-de.org/forum/attachments/39/07/9466654-sftp.txt

Was habe ich gemacht...:

  • #1 user anlegen

  • useradd -g sftpgroup -s /usr/sbin/nologin tom

  • #2 Passwort vergeben

  • passwd tom

  • #3 Verzeichnis anlegen

  • mkdir /mnt/backup_pool/sftp_pool/tom

  • #4 Eigentümer ändern

  • chown tom:sftpgroup /mnt/backup_pool/sftp_pool/tom/

  • #5 Rechte setzen

  • chmod 700 /mnt/backup_pool/sftp_pool/tom/

  • #6 sshd_conf anpassen

Match Group sftpgroup
        ChrootDirectory /mnt/backup_pool/sftp_pool/tom/
        X11Forwarding no
        AllowTcpForwarding no
        ForceCommand internal-sftp -d /%u
        AllowAgentForwarding no
        PermitTunnel no
        PasswordAuthentication yes

Tja... und dann - habe ich gedacht - sollte es funktionieren... Tut es aber nicht...

Wäre sehr dankbar, wenn mir jemand sagen könnte, wo ich genauer hinschauen muss.

Vielen Dank!

Bearbeitet von sebix:

Bitte verwende in Zukunft Codeblöcke, um die Übersicht im Forum zu verbessern!

Bearbeitet von sebix:

Bitte verwende in Zukunft Listen, um die Übersicht im Forum zu verbessern!

sftp.txt (14.4 KiB)
Download sftp.txt

micneu

Avatar von micneu

Anmeldungsdatum:
19. Januar 2021

Beiträge: 683

Wohnort: Hamburg

SFTP ist einfach ssh, wenn dein ssh richtig konfiguriert ist sollte es gehen, wie hast du was konfiguriert, bitte die Ausgabe deiner Konfiguration in einem codeblock

% sftp raspi51
Connected to raspi51.
sftp>

probiere es doch erstmal von einem Linux system nicht über Windoof am besten setzt du nochmal ein frisches Ubuntu auf an dem du nur ssh installierts/aktivierst. Ich habe an meinem System keine großen änderungen gemacht, läuft out of the box

DerTom246

(Themenstarter)

Anmeldungsdatum:
16. Januar 2021

Beiträge: 8

micneu schrieb:

SFTP ist einfach ssh, wenn dein ssh richtig konfiguriert ist sollte es gehen, wie hast du was konfiguriert, bitte die Ausgabe deiner Konfiguration in einem codeblock

% sftp raspi51
Connected to raspi51.
sftp>

probiere es doch erstmal von einem Linux system nicht über Windoof

Das ist die zugehörige sshd_conf

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

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

# 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.
#
# In general, the first uncommented definition of an option takes precedence.
# For options that accept multiple values, like 'Port', subsequent definitions
# are appended to the configuration.
#
# Note that the above implies that configuration options from snippets in
# /etc/ssh/sshd_config.d/*.conf take precedence over those defined in this
# file. In addition, configuration snippet files are processed in lexical
# order, so options defined in files with names that sort earlier take
# precedence.
#
# Such configuration snippets may be present in default installations of
# Ubuntu.
Include /etc/ssh/sshd_config.d/*.conf

# When systemd socket activation is used (the default), the socket
# configuration must be re-generated after changing Port, AddressFamily, or
# ListenAddress.
#
# For changes to take effect, run:
#
#   systemctl daemon-reload
#   systemctl restart ssh.socket
#

Port 22
#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 prohibit-password
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

PubkeyAuthentication yes

# 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
#PermitEmptyPasswords no

# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
KbdInteractiveAuthentication 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 KbdInteractiveAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via KbdInteractiveAuthentication may bypass
# the setting of "PermitRootLogin prohibit-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and KbdInteractiveAuthentication to 'no'.
UsePAM yes

#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
PrintMotd no
#PrintLastLog yes
#TCPKeepAlive yes
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS no
#PidFile /run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#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

# allowed users
AllowUsers tom tom-test

# settings sftp-server for group sftp-group
Match Group sftpgroup
        ChrootDirectory /mnt/backup_pool/sftp_pool/tom/
        X11Forwarding no
        AllowTcpForwarding no
        ForceCommand internal-sftp -d /%u
        AllowAgentForwarding no
        PermitTunnel no
        PasswordAuthentication yes

micneu

Avatar von micneu

Anmeldungsdatum:
19. Januar 2021

Beiträge: 683

Wohnort: Hamburg

DerTom246 schrieb:

  • useradd -g sftpgroup -s /usr/sbin/nologin tom

wie soll das gehen wenn er sich nicht anmelden darf?

  • bitte die verzeichnis rechte zeigen recursiv im codeblock

/mnt/backup_pool
  • hier könnte ein fehler sein, woher hast du die angaben?

ForceCommand internal-sftp -d /%u

DerTom246

(Themenstarter)

Anmeldungsdatum:
16. Januar 2021

Beiträge: 8

micneu schrieb:

DerTom246 schrieb:

  • useradd -g sftpgroup -s /usr/sbin/nologin tom

wie soll das gehen wenn er sich nicht anmelden darf?

  • bitte die verzeichnis rechte zeigen recursiv im codeblock

/mnt/backup_pool
  • hier könnte ein fehler sein, woher hast du die angaben?

ForceCommand internal-sftp -d /%u

Mit der Option '-s /usr/sbin/nologin' kriegt der sftp-user keine Shell - wenn ich die Erläuterungen richtig gelesen habe, dann hat dies für den sftp-Dienst keine Auswirkung.

Hier die Abfrage der Rechte:

/mnt/backup_pool/
total 2
drwxrwxr-x 4 root root  4 Feb 22 14:04 .
drwxr-xr-x 1 root root 22 Feb 21 18:26 ..
drwxr-xr-x 3 root root  3 Feb 22 14:04 minio_pool-dont_touch
drwxr-xr-x 3 root root  3 Feb 23 12:41 sftp_pool
/mnt/backup_pool/sftp_pool/
total 2
drwxr-xr-x 3 root    root      3 Feb 23 12:41 .
drwxrwxr-x 4 root    root      4 Feb 22 14:04 ..
drwx------ 2 tom     sftpgroup 2 Feb 23 12:41 tom

Die Zeile

ForceCommand internal-sftp -d /%u

habe ich aus einem howto kopiert...

Hier mal ein Einwahlversuch aus einem Linux-Terminal:

sftp -v tom@10.0.0.4
OpenSSH_9.9p1 Ubuntu-3ubuntu3, OpenSSL 3.4.1 11 Feb 2025
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Reading configuration data /etc/ssh/ssh_config.d/20-systemd-ssh-proxy.conf
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug1: Connecting to 10.0.0.4 [10.0.0.4] port 22.
debug1: Connection established.
debug1: identity file /home/tom-a/.ssh/id_rsa type -1
debug1: identity file /home/tom-a/.ssh/id_rsa-cert type -1
debug1: identity file /home/tom-a/.ssh/id_ecdsa type -1
debug1: identity file /home/tom-a/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/tom-a/.ssh/id_ecdsa_sk type -1
debug1: identity file /home/tom-a/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /home/tom-a/.ssh/id_ed25519 type -1
debug1: identity file /home/tom-a/.ssh/id_ed25519-cert type -1
debug1: identity file /home/tom-a/.ssh/id_ed25519_sk type -1
debug1: identity file /home/tom-a/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /home/tom-a/.ssh/id_xmss type -1
debug1: identity file /home/tom-a/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_9.9p1 Ubuntu-3ubuntu3
debug1: Remote protocol version 2.0, remote software version OpenSSH_9.9p1 Ubuntu-3ubuntu3
debug1: compat_banner: match: OpenSSH_9.9p1 Ubuntu-3ubuntu3 pat OpenSSH* compat 0x04000000
debug1: Authenticating to 10.0.0.4:22 as 'tom'
debug1: load_hostkeys: fopen /home/tom-a/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: sntrup761x25519-sha512
debug1: kex: host key algorithm: ssh-ed25519
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: SSH2_MSG_KEX_ECDH_REPLY received
debug1: Server host key: ssh-ed25519 SHA256:XXX
debug1: load_hostkeys: fopen /home/tom-a/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: Host '10.0.0.4' is known and matches the ED25519 host key.
debug1: Found key in /home/tom-a/.ssh/known_hosts:1
debug1: ssh_packet_send2_wrapped: resetting send seqnr 3
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: Sending SSH2_MSG_EXT_INFO
debug1: expecting SSH2_MSG_NEWKEYS
debug1: ssh_packet_read_poll2: resetting read seqnr 3
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 134217728 blocks
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_ext_info_client_parse: server-sig-algs=<ssh-ed25519,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,sk-ssh-ed25519@openssh.com,sk-ecdsa-sha2-nistp256@openssh.com,rsa-sha2-512,rsa-sha2-256>
debug1: kex_ext_info_check_ver: publickey-hostbound@openssh.com=<0>
debug1: kex_ext_info_check_ver: ping@openssh.com=<0>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_ext_info_client_parse: server-sig-algs=<ssh-ed25519,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,sk-ssh-ed25519@openssh.com,sk-ecdsa-sha2-nistp256@openssh.com,rsa-sha2-512,rsa-sha2-256>
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Will attempt key: /home/tom-a/.ssh/id_rsa
debug1: Will attempt key: /home/tom-a/.ssh/id_ecdsa
debug1: Will attempt key: /home/tom-a/.ssh/id_ecdsa_sk
debug1: Will attempt key: /home/tom-a/.ssh/id_ed25519
debug1: Will attempt key: /home/tom-a/.ssh/id_ed25519_sk
debug1: Will attempt key: /home/tom-a/.ssh/id_xmss
debug1: Trying private key: /home/tom-a/.ssh/id_rsa
debug1: Trying private key: /home/tom-a/.ssh/id_ecdsa
debug1: Trying private key: /home/tom-a/.ssh/id_ecdsa_sk
debug1: Trying private key: /home/tom-a/.ssh/id_ed25519
debug1: Trying private key: /home/tom-a/.ssh/id_ed25519_sk
debug1: Trying private key: /home/tom-a/.ssh/id_xmss
debug1: Next authentication method: password
tom@10.0.0.4's password:
Authenticated to 10.0.0.4 ([10.0.0.4]:22) using "password".
debug1: channel 0: new session [client-session] (inactive timeout: 0)
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: pledge: filesystem
Read from remote host 10.0.0.4: Connection reset by peer
client_loop: send disconnect: Broken pipe
Connection closed

micneu

Avatar von micneu

Anmeldungsdatum:
19. Januar 2021

Beiträge: 683

Wohnort: Hamburg

So wie ich das sehe

  • Deine Datei rechte auf das Verzeichnis stimmen nicht (müsste root sein)

  • Deine sshd_conf ist nicht richtig (wie schon geschrieben)

Ich habe es bei mir mal nachgestellt und es funktioniert, wenn man es RICHTIG konfiguriert

PS: keine Ahnung welches HowTo du beachtest, das ist Falsch

DerTom246

(Themenstarter)

Anmeldungsdatum:
16. Januar 2021

Beiträge: 8

micneu schrieb:

So wie ich das sehe

  • Deine Datei rechte auf das Verzeichnis stimmen nicht (müsste root sein)

  • Deine sshd_conf ist nicht richtig (wie schon geschrieben)

Ich habe es bei mir mal nachgestellt und es funktioniert, wenn man es RICHTIG konfiguriert

PS: keine Ahnung welches HowTo du beachtest, das ist Falsch

OK, danke für Deine Mühe.

Habe die Rechte für das Verzeichnis auf root:root gesetzt und in der sshd_conf die Zeile auf 'ForceCommand internal-sftp' geändert.

Läuft aber leider noch immer nicht...

micneu

Avatar von micneu

Anmeldungsdatum:
19. Januar 2021

Beiträge: 683

Wohnort: Hamburg

Dann bin ich raus, mehr kann ich nicht machen. Ich konnte es bei mir erfolgreich testen.

 % sftp tom@raspi51
tom@raspi51's password:
Connected to raspi51.
sftp>

DerTom246

(Themenstarter)

Anmeldungsdatum:
16. Januar 2021

Beiträge: 8

So... bin nun durch diverse andere Distributionen durch und hatte überall diesen blöden Fehler...

Falls jemand auch damit kämpft, einfach mal schauen, ob in der sshd_config die Zeile 'PermitRootLogin yes' fehlt bzw. auskommentiert wurde.

Jetzt funktioniert es. sshd nutzt wohl den root-user!

Viele Grüße

micneu

Avatar von micneu

Anmeldungsdatum:
19. Januar 2021

Beiträge: 683

Wohnort: Hamburg

Nicht vergessen auf gelöst zu stellen

Antworten |