staging.inyokaproject.org

Auführen von script bei FTP Verbindung

Status: Ungelöst | Ubuntu-Version: Ubuntu 16.04 (Xenial Xerus)
Antworten |

Danloc

Avatar von Danloc

Anmeldungsdatum:
4. April 2017

Beiträge: Zähle...

Hallo zusammen,

ich habe ein kleines Problem und konnte im Netz leider nichts passendes dazu finden.

und zwar:

Ich hab einen vsftp Server der so configuriert ist, dass die zugelassenen Benutzer mittles chroot in ihrem jail landen. (FTP über TLS) Jeder Benutzer bekommt andere Ordner mittles mount -o ins chroot eingebunden, sodass der Zugriff nur auf diese Verzeichnisse möglich ist.

soweit so gut ...

Jetzt möchte ich für jeden Benutzer eine Liste mit Ordnernamen erstellen, welche dann für den jweiligen Benutzer in das entsprechende chroot Verzeichnis eingebunden werden. Mein Problem hierbei ist allerdings, dass ich nicht weiß ich wie ein "Startscript" bei FTP Login ausführe.

Mit .bashrc bei einem ssh login besispielsweise klappt das ganze wunderbar. Gibt es so etwas auch für FTPlogins bzw. kann ich irgendwie die .bashrc auch bei FTP logins verwenden?

Ich hoffe jemand hat einen guten Tipp

In diesem Sinne schonmal viele Dank, Danloc

misterunknown Team-Icon

Ehemalige
Avatar von misterunknown

Anmeldungsdatum:
28. Oktober 2009

Beiträge: 4403

Du kannst dir ein PAM-Modul stricken was deine Aktionen ausführt, das ist aber nicht trivial. Hier gibts einen Überblick, wie PAM funktioniert.

Danloc

(Themenstarter)
Avatar von Danloc

Anmeldungsdatum:
4. April 2017

Beiträge: Zähle...

Danke für die schnelle Antwort.

Ich habe jetzt hin und her überlegt, ob ich nun ein PAM-Modul basteln will, oder doch eine andere Lösung für meinen Anwendungsfall versuchen werde. Ich habe mich erstmal für etwas anderes entschieden.

Und zwar..

Werde ich FTP über den ssh daemon laufen lassen, also sftp und nicht mehr FTP over TLS mit vsftp. Also wieder alles umkonfiguriert .. soweit dass, wie auch mein vsftp server Funktioniert - Benutzer kann sich anmelden und landet in seinem Home-Jail.

Wenn ich es richtig verstehe, sollte eine sftp Verbindung eine non-login-shell darstellen. und die Dateien /etc/profile.. → ~/.bash_profile → ~/.profile usw. bei user login ausführen.

Sollte sftp eine non login shell darstellen, sollten die Dateien /etc/profile.. → ~/.bashrc bei user login ausführt werden.

When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior.

When an interactive shell that is not a login shell is started, bash reads and executes commands from /etc/bash.bashrc and ~/.bashrc, if these files exist. This may be inhibited by using the --norc option. The --rcfile file option will force bash to read and execute commands from file instead of /etc/bash.bashrc and ~/.bashrc.

Ich habe alle Wege versucht. sowohl /etc/profile/... ~/.bashrc ~/.bash_profile ~/.profile usw ... Allerdings wird keine dieser Dateien ausgeführt, wenn ich mich Mitells FileZilla verbinde. Mit einer ssh-Verbindung übers Terminal (z.B. Putty) also bei einer login-shell funktioniert das ganze wunderbar.

Kann ich dem ssh daemon irgendwo mitteilen, ob profiles für user logins, bei non-login shells geladen werden sollen oder nicht?

Hier mal die Einstellungen, die meiner Meinung nach relevant sein könnten:

passwd für den testuser (1003 = gid für sambauser):

1
testuser:x:1005:1003:test,123,,:/FTPhome/testuser:/bin/bash

/etc/ssh/sshd_config

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104

# Package generated configuration file
# See the sshd_config(5) manpage for details

# What ports, IPs and protocols we listen for
Port 22
# Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress ::
#ListenAddress 0.0.0.0
Protocol 2
# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
#Privilege Separation is turned on for security
UsePrivilegeSeparation yes

# Lifetime and size of ephemeral version 1 server key
KeyRegenerationInterval 3600
ServerKeyBits 1024

# Logging
SyslogFacility AUTH
LogLevel INFO

# Authentication:
LoginGraceTime 120
#PermitRootLogin without-password
PermitRootLogin yes
StrictModes yes

RSAAuthentication yes
PubkeyAuthentication yes
#AuthorizedKeysFile     %h/.ssh/authorized_keys

# Don't read the user's ~/.rhosts and ~/.shosts files
IgnoreRhosts yes
# For this to work you will also need host keys in /etc/ssh_known_hosts
RhostsRSAAuthentication no
# similar for protocol version 2
HostbasedAuthentication no
# Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication
#IgnoreUserKnownHosts yes

# To enable empty passwords, change to yes (NOT RECOMMENDED)
PermitEmptyPasswords no

# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no

# Change to no to disable tunnelled clear text passwords
#PasswordAuthentication yes

# Kerberos options
#KerberosAuthentication no
#KerberosGetAFSToken no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes

X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
#UseLogin no

#MaxStartups 10:30:60
#Banner /etc/issue.net

# Allow client to pass locale environment variables
AcceptEnv LANG LC_*

#Subsystem sftp /usr/lib/openssh/sftp-server




# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
UsePAM yes

#DenyUsers danloc


Subsystem sftp /usr/lib/ssh/sftp-server

Match Group sambauser
  ChrootDirectory %h
  ForceCommand internal-sftp
  AllowTcpForwarding no
  X11Forwarding no

Sollte jemand eine Idee haben, woran es liegen könnte wäre ich sehr dankbar.

Vielen Dank, Danloc

misterunknown Team-Icon

Ehemalige
Avatar von misterunknown

Anmeldungsdatum:
28. Oktober 2009

Beiträge: 4403

Danloc schrieb:

Wenn ich es richtig verstehe, sollte eine sftp Verbindung eine non-login-shell darstellen.

Nun, es ist gar keine vollwertige Shell, sondern eine bereitgestellte Schnittstelle vom SFTP-Server.

und die Dateien /etc/profile.. → ~/.bash_profile → ~/.profile usw. bei user login ausführen.

Nein, AFAIK nicht.

Kann ich dem ssh daemon irgendwo mitteilen, ob profiles für user logins, bei non-login shells geladen werden sollen oder nicht?

Ich vermute nicht. Es würde dir auch nichts nützen, denn all diese Sachen werden unter dem Nutzer ausgeführt, und nicht als root. Von daher kannst du den Mount-Befehl an dieser Stelle eh nicht nutzen.

Ich würde an deiner Stelle die Verzeichnisse nicht erst beim Login mounten, sondern ständig. Das frisst ja kein Brot.

Antworten |