root login

AllOnline

New Member
Hallo,

ich habe normalerweise den Server so eingerichtet, das man sich nur auf der Shell mit Passwort anmelden kann und das der Login auf root nicht funktioniert. Nun möchte ich doch verschiedene Sachen (wie Logs) gerne über WinSCP anschauen.

Dazu habe ich nun versucht den Login für root auf sftp zu beschränken und dies dann der Login nur mit Pub-Key funktioniert.
Hier mal meine Konfigurationen:

sshd_config
Code:
Port 22
Protocol 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
UsePrivilegeSeparation yes
KeyRegenerationInterval 3600
ServerKeyBits 768
SyslogFacility AUTH
LogLevel VERBOSE
LoginGraceTime 120
PermitRootLogin forced-commands-only
StrictModes yes

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

IgnoreRhosts yes
...

PermitEmptyPasswords no
ChallengeResponseAuthentication no

X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes

AcceptEnv LANG LC_*
Subsystem sftp /usr/lib/openssh/sftp-server

UsePAM yes
Match User root
  ForceCommand /usr/lib/misc/sftp-server

mit dem rsa keys habe ich nun schon x-mal rumgespielt. Ob über putty erstellt konvertiert und eingepfelgt oder mir den private key vom server gezogen.... Ich komme immer zum gleichem Fehler.

Einloggen in WinSCP, dann eingabe des Schlüssels für private Key und dann kommt access diened (Schlüssel für privatekey ist richtig) und erneute Passwort eingabe auforderung. Wenn der Private-Schlüssel falsch wäre kommt ne andere Meldung.

Im Server Log sehe ich sowas:
Code:
Oct 31 10:55:01 c061 CRON[24444]: pam_unix(cron:session): session opened for user root by (uid=0)
Oct 31 10:55:01 c061 CRON[24444]: pam_unix(cron:session): session closed for user root
Oct 31 10:55:04 c061 sshd[24446]: Set /proc/self/oom_adj to 0
Oct 31 10:55:04 c061 sshd[24446]: Connection from 24.147.175.78 port 55883
Oct 31 10:55:07 c061 sshd[24446]: Failed none for root from 24.147.175.78 port 55883 ssh2
Oct 31 10:55:07 c061 sshd[24446]: Found matching RSA key: a1:0c:f8:84:25:6b:08:53:d5:6a:3a:46:3b:78:fd:ce
Oct 31 10:55:07 c061 sshd[24446]: Found matching RSA key: a1:0c:f8:84:25:6b:08:53:d5:6a:3a:46:3b:78:fd:ce
Oct 31 10:55:07 c061 sshd[24446]: ROOT LOGIN REFUSED FROM 24.147.175.78
Oct 31 10:55:07 c061 sshd[24446]: Failed publickey for root from 24.147.175.78 port 55883 ssh2
einer eine Idee?
 
Mit den Ports ist doch erst mal alles OK. Sein PC hat die IP 24.147.175.78 und verbindet von Port 55883 auf den SSH-Port auf seinem Server.
 
Dort steht from und nicht to ;)
Das Problem sollte hier liegen:
PermitRootLogin forced-commands-only

ist das nicht richtig um es auf die unten stehenden Bedingungen zu verbinden?
also sftp only?

Match User root
ForceCommand /usr/lib/misc/sftp-server

Hab gerade noch einen Fehler gefunden - dort steht misc/sftp-server - das hab ich mal durch den richtigen Pfad ersetzt.
Ändert aber nichts an den Fehlern:

Code:
Oct 31 14:17:48 c061 sshd[25561]: Set /proc/self/oom_adj to 0
Oct 31 14:17:48 c061 sshd[25561]: Connection from clientip port 49785
Oct 31 14:17:49 c061 sshd[25561]: Failed none for root from clientip port 49785 ssh2
Oct 31 14:17:49 c061 sshd[25561]: Found matching RSA key: a1:0c:f8:84:25:6b:08:53:d5:6a:3a:46:3b:78:fd:ce
Oct 31 14:17:54 c061 sshd[25561]: Found matching RSA key: a1:0c:f8:84:25:6b:08:53:d5:6a:3a:46:3b:78:fd:ce
Oct 31 14:17:54 c061 sshd[25561]: ROOT LOGIN REFUSED FROM clientip
Oct 31 14:17:54 c061 sshd[25561]: Failed publickey for root from clientip port 49785 ssh2
 
Last edited by a moderator:
Lies nochmal ganz genau in sshd_config(5) nach, unter welchen Umständen PermitRootLogin forced-commands-only funktioniert.

If this option is set to ``forced-commands-only'', root login
with public key authentication will be allowed, but only if the
command option has been specified (which may be useful for taking
remote backups even if root login is normally not allowed). All
other authentication methods are disabled for root.

Ja ich hab doch die command option spezifiziert oder nicht?

Code:
Match User root
  ForceCommand /usr/lib/.../sftp-server
 
Damit ist die command-Option direkt im Key (der in ~/.ssh/authorized_keys) gemeint. Lies dazu den Abschnitt AUTHORIZED_KEYS FILE FORMAT in sshd(8)

Entschuldigung, aber könntest du mir auf die Sprünge helfen?
Trotz dem text weiß ich nicht wie ich es machen soll:
command="command"
Specifies that the command is executed whenever this key is used for authentication. The command supplied by the user (if any) is ignored. The command is run on a pty if the client requests a pty; otherwise it is run without a tty. If an 8-bit clean channel is required, one must not request a pty or should specify no-pty. A quote may be included in the command by quoting it with a backslash. This option might be useful to restrict certain public keys to perform just a specific operation. An example might be a key that permits remote backups but nothing else. Note that the client may specify TCP and/or X11 forwarding unless they are explicitly prohibited. The command originally supplied by the client is available in the SSH_ORIGINAL_COMMAND environment variable. Note that this option applies to shell, command or subsystem execution. Also note that this command may be superseded by either a sshd_config(5) ForceCommand directive or a command embedded in a certificate.

Wie muss ich vorgehen?
 
Hey,

also mit sftp-server funktioniert es.
Was ist internal sftp wenn ich fragen darf? Hab es noch nicht auf meinem Server (gefunden).
 
Hallo und entschuldigt,
dass ich den Thread wieder ausgrabe.

Aktuell läuft eigentlich alles, dank euerer Hilfe!!
Allerdings möchte ich mich jetzt, wie es sich gehört, mit publickey einloggen.
Also in die authorzed_keys neue Zeile eingefügt. Allerdings funktioniert es nicht!

Im Log steht falsches Passwort für User root...

Ist dort wieder command="..." nötig, obwohl dieser user alles machen können soll?

authorized_keys:
Code:
command="/usr/lib/openssh/sftp-server" ssh-rsa A.... imported-openssh-key
ssh-rsa A... rsa-key-20120213

/etc/ssh/sshd_config
Code:
LoginGraceTime 120
PermitRootLogin forced-commands-only
StrictModes yes

#seperate with space
AllowUsers xyz root

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

...

Match User root
  ForceCommand /usr/lib/openssh/sftp-server
 
Last edited by a moderator:
Ist dort wieder command="..." nötig, obwohl dieser user alles machen können soll?
Was denn nun? Soll root bei direktem Login nur sftp oder wie üblich Alles dürfen? Du musst Dich zwischen beiden Möglichkeiten entscheiden.

Alternativ sei auf su verwiesen.
 
Ich möchte, dass sich root über key einloggen kann und es zusätzlich einen speziellen sftp key gibt.
Alle anderen Clients sollen sich noch normal über Passwort einloggen können...
 
Roger Wilco hat doch bereits darauf verwiesen das Du den von Dir zitierten Abschnitt verstehen sollst.
Du kannst "sftp" auch per authorized_keys erzwingen anstatt die sshd_config zu nutzen. Allerdings solltest Du dann sicher stellen, daß der sftp-User " ~/.ssh/authorized_keys" nicht ändern kann.
Ansonsten klingt das so als ob Du Personen Rechte einräumen willst denen Du nicht voll vertraust, aber auch nicht weißt wie Du die Rechte sauber einschränken kannst.
 
Hey,

danke für deine Antwort, das Zitat hab ich schon verstanden, deswegen such ich nach alternativen.
Ich möchte folgendes verbinden:

  1. Nomale Nutzer sollen sich mit key und/oder passwort einloggen können
  2. Root soll sich nur mit key einloggen können
  3. Es soll einen Key geben, der nur WinSCP über root kann

Vielen Dank für eure Hilfe!
 
Back
Top