winscp rootlogin und PermitRootLogin

Backup, Restore und Transfer von Daten
mpl
Posts: 48
Joined: 2006-06-07 12:22
 

winscp rootlogin und PermitRootLogin

Post by mpl »

hi leute ^^ ich stehe vor einem problem... unswar habe ich den rootlogin deaktiviert... und jetz komme ich ja auch per winscp und root nicht mehr rein... und mit dem normalen user reichen mir die rechte im winscp leider nicht aus gibts da irgendwie nen weg sich trotzdem per root noch einloggen zu können mit winscp?

danke für eure hilfe

mfg MPL
User avatar
daemotron
Administrator
Administrator
Posts: 2641
Joined: 2004-01-21 17:44
 

Re: winscp rootlogin und PermitRootLogin

Post by daemotron »

Baue folgendes in Deine sshd_config ein:

Code: Select all

PermitRootLogin forced-commands-only

Subsystem sftp /usr/lib/misc/sftp-server

# Am Ende der Datei
Match User root
  ForceCommand /usr/lib/misc/sftp-server
Danach solltest Du in der Lage sein, als root per sftp auf den Server zuzugreifen (aber nur, wenn Du Pubkey-Authentifizierung benutzt). Alle anderen Login-Versuche als root werden aber weiterhin abgeblockt. (siehe man sshd_config)
mpl
Posts: 48
Joined: 2006-06-07 12:22
 

Re: winscp rootlogin und PermitRootLogin

Post by mpl »

ah dank dir
mpl
Posts: 48
Joined: 2006-06-07 12:22
 

Re: winscp rootlogin und PermitRootLogin

Post by mpl »

/etc/init.d/ssh restart
/etc/ssh/sshd_config: line 75: Bad configuration option: Match
/etc/ssh/sshd_config: line 76: Bad configuration option: ForceCommand
/etc/ssh/sshd_config: terminating, 2 bad configuration options


hier die datei...

Code: Select all

# Package generated configuration file
# See the sshd(8) 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
#Privilege Separation is turned on for security
UsePrivilegeSeparation yes

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

# Logging
SyslogFacility AUTH
LogLevel INFO

# Authentication:
LoginGraceTime 600
PermitRootLogin forced-commands-only 
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 no to disable s/key passwords
#ChallengeResponseAuthentication yes

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


# To change Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#AFSTokenPassing no
#KerberosTicketCleanup no

# Kerberos TGT Passing does only work with the AFS kaserver
#KerberosTgtPassing yes

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

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

Subsystem	sftp	/usr/lib/sftp-server

UsePAM yes

Match User root 
ForceCommand /usr/lib/sftp-server 
Roger Wilco
Posts: 5923
Joined: 2004-05-23 12:53
 

Re: winscp rootlogin und PermitRootLogin

Post by Roger Wilco »

Dein sshd ist vermutlich zu alt. Die Direktiven Match und ForceCommand werden erst mit OpenSSH 4.4 unterstützt.
mpl
Posts: 48
Joined: 2006-06-07 12:22
 

Re: winscp rootlogin und PermitRootLogin

Post by mpl »

und wie kann ichs updaten^^? apt-get update und der bla sagt nix
der kleine tux
Posts: 97
Joined: 2005-10-29 04:12
Location: Planet Erde
 

Re: winscp rootlogin und PermitRootLogin

Post by der kleine tux »

Nabend
Stable ist derzeit bei Debian OpenSSH_4.3p2
und wie kann ichs updaten^^? apt-get update und der bla sagt nix
:roll: das solltest du mal deinen Admin fragen :twisted:

ftp://ftp.ca.openbsd.org/pub/OpenBSD/OpenSSH/portable/
und INSTALL lesen 8O

Gruß
User avatar
daemotron
Administrator
Administrator
Posts: 2641
Joined: 2004-01-21 17:44
 

Re: winscp rootlogin und PermitRootLogin

Post by daemotron »

Wenn ein Upgrade von OpenSSH gar nicht möglich ist, bleibt immer noch die Möglichkeit, PermitRootLogin auf yes zu setzen - dann aber bitte root eine auf sftp bzw. scp eingeschränkte Shell zuweisen; es würde sich z. B. rssh anbieten. Außerdem musst Du dann selbst darauf achten, dass nur Public Key Authentifizierung möglich ist...

Um auf dem Server dennoch mit root-Rechten arbeiten zu können, einfach für den normalen Arbeitsuser einen Alias in der .bashrc anlegen (für Faule), der dann so aussieht (oder das Kommando eben so eintippen):

Code: Select all

alias bigboss='su -l -s /bin/bash root'
ACHTUNG, WARNUNG: Dieser Workaraound ist unsauber und weniger sicher als die Realisierung über ForcedCommands!!!
mpl
Posts: 48
Joined: 2006-06-07 12:22
 

Re: winscp rootlogin und PermitRootLogin

Post by mpl »

Der kleine Tux wrote:Nabend
Stable ist derzeit bei Debian OpenSSH_4.3p2
und wie kann ichs updaten^^? apt-get update und der bla sagt nix
:roll: das solltest du mal deinen Admin fragen :twisted:

ftp://ftp.ca.openbsd.org/pub/OpenBSD/OpenSSH/portable/
und INSTALL lesen 8O

Gruß
ich bin mein admin^^ hab stable sources blos drine.. und naja die sache sieht so bei mir grad aus^^

Code: Select all

ssh -v
OpenSSH_3.8.1p1 Debian-8.sarge.6, OpenSSL 0.9.7e 25 Oct 2004
der ftp von dir geht leider nicht
der kleine tux
Posts: 97
Joined: 2005-10-29 04:12
Location: Planet Erde
 

Re: winscp rootlogin und PermitRootLogin

Post by der kleine tux »

Nabend
ich bin mein admin^^
je ne ist klar 8) dann soltest du am Wochenende
eventuel mal auf Etch Upgraden sofern es möglich ist...

Gruß
mpl
Posts: 48
Joined: 2006-06-07 12:22
 

Re: winscp rootlogin und PermitRootLogin

Post by mpl »

naja ich weissnet is mir bissl riskant das am ende alles futsch geht....
der kleine tux
Posts: 97
Joined: 2005-10-29 04:12
Location: Planet Erde
 

Re: winscp rootlogin und PermitRootLogin

Post by der kleine tux »

Hallo

was sollte daran Riskant sein ? ok es macht ein wenig arbeit aber mit Backups ist man da auf der sicheren seite

gruß
mpl
Posts: 48
Joined: 2006-06-07 12:22
 

Re: winscp rootlogin und PermitRootLogin

Post by mpl »

jo ma guggn setze mich heute abend ran und mache es
fireball
Posts: 13
Joined: 2006-01-06 11:22
 

Re: winscp rootlogin und PermitRootLogin

Post by fireball »

Servus,
ich würde das auch gern so machen, dass root nur mit Zertifikat auf WinSCP möglich ist. Leider klappt es nicht.
Dist: openSUSE 10.2
SSH: openSSH 4.4

Habe mit

Code: Select all

ssh-keygen -t rsa
ein Zertifikat erstellt und den Public Key auf den Server kopiert. Danach noch mit

Code: Select all

cat id_rsa.pub >> ~/.ssh/authorized_keys
der Liste der erlaubten Keys hinzugefügt.
Keyfile hat in dem speziellen Testfall keine passphrase

Login klappt danach mit Zertifikat und ohne.

Folgende Änderungen habe ich wie oben beschrieben gemacht:

Code: Select all

PermitRootLogin forced-commands-only
Match User root
	ForceCommand /usr/lib/ssh/sftp-server
Subsystem steht bei Suse standardmäßig schon drin. Ist allerdings ein anderer Pfad, da andere Dist.
Folgende Einstellungen sind bei Suse Standard. Es geht aber auch nicht, wenn ich sie extra einbaue.

Code: Select all

RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile	.ssh/authorized_keys
PasswordAuthentication no
Leider frägt er mich beim Login jetzt nach einem Passwort. WinSCP zeigt folgendes:
Using username 'root'
Authenticating with public key 'importet-openssh-key'
Access denied
und dann kommt die Frage nach dem Passwort.

Hat einer von euch ne Ahnung was ich noch ändern muss?
michi123
Posts: 73
Joined: 2010-08-04 17:45
 

Re: winscp rootlogin und PermitRootLogin

Post by michi123 »

hey leute, ich poste einfach mal hier in diesem thread, weils ums selbe thema geht und ich hier im forum keinen weiteren finden kann. hoffe ihr seid mir nicht böse weil der thread schon sooo alt ist!
wie der thread schon sagt, kann ich mich mit winscp in verbindung mit nem key nicht einloggen :(. hab schon sämtliche man pages durchgelesen und google jetzt schon 2 tage im inet rum. meinen ssh server hab ich jetzt glaub ich in den letzten 2 tagen 100 mal neu gestartet lol. aber leider ohne erfolg!
mit nem normalen user+key kann ich mich an der console ohne probleme anmelden, nur mit root über winscp funzts leider nicht. der root key befindet sich in der datei /root/.ssh/authorized_keys. den key hab ich wie jene von den normalen usern mit puttygen erstellt (dsa 2048bits) - dateirechte sind auf .ssh 0700 und authorized_keys 0600 gesetzt.

system: SSH-2.0-OpenSSH_5.1p1 Debian-5
meine sshd_config sieht wie folgt aus:

Code: Select all

Port x
Protocol 2

HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key

UsePrivilegeSeparation yes

SyslogFacility AUTH
LogLevel INFO

LoginGraceTime 30
PermitRootLogin forced-commands-only
StrictModes yes
MaxAuthTries 3

RSAAuthentication no
PubkeyAuthentication yes
AuthorizedKeysFile %h/.ssh/authorized_keys
IgnoreRhosts yes
RhostsRSAAuthentication no
HostbasedAuthentication no

#IgnoreUserKnownHosts yes
PermitEmptyPasswords no
ChallengeResponseAuthentication no
PasswordAuthentication no

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

# GSSAPI options
GSSAPIAuthentication no
#GSSAPICleanupCredentials yes

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

MaxStartups 3:30:10
Banner /etc/issue.net

AcceptEnv LANG LC_*

UsePAM no
GatewayPorts no
AllowTcpForwarding no
KeepAlive yes

Subsystem sftp /usr/lib/sftp-server

Match User root
ForceCommand /usr/lib/sftp-server
ob da jetzt bei subsystem bzw. forcecommand /usr/lib/openssh/sftp-server oder /usr/lib/sftp-server steht bleibt egal (klar, weil nur symlink), aber man hofft ja immer^^

das gibt winscp aus:

Code: Select all

. 2010-08-04 18:19:55.281 WinSCP Version 4.2.8 (Build 818) (OS 6.1.7600)
. 2010-08-04 18:19:55.281 Login time: Mittwoch, 04. August 2010 18:19:55
. 2010-08-04 18:19:55.281 --------------------------------------------------------------------------
. 2010-08-04 18:19:55.281 Session name: xx.xx.xx.xx
. 2010-08-04 18:19:55.281 Host name: xx.xx.xx.xx (Port: x)
. 2010-08-04 18:19:55.281 User name: root (Password: No, Key file: Yes)
. 2010-08-04 18:19:55.281 Tunnel: No
. 2010-08-04 18:19:55.281 Transfer Protocol: SFTP (SCP)
. 2010-08-04 18:19:55.281 Ping type: -, Ping interval: 30 sec; Timeout: 15 sec
. 2010-08-04 18:19:55.281 Proxy: none
. 2010-08-04 18:19:55.281 SSH protocol version: 2; Compression: No
. 2010-08-04 18:19:55.281 Bypass authentication: No
. 2010-08-04 18:19:55.282 Try agent: Yes; Agent forwarding: No; TIS/CryptoCard: No; KI: Yes; GSSAPI: No
. 2010-08-04 18:19:55.282 Ciphers: aes,blowfish,3des,WARN,arcfour,des; Ssh2DES: No
. 2010-08-04 18:19:55.282 SSH Bugs: -,-,-,-,-,-,-,-,-
. 2010-08-04 18:19:55.282 SFTP Bugs: -,-
. 2010-08-04 18:19:55.282 Return code variable: Autodetect; Lookup user groups: Yes
. 2010-08-04 18:19:55.282 Shell: default
. 2010-08-04 18:19:55.282 EOL: 0, UTF: 2
. 2010-08-04 18:19:55.282 Clear aliases: Yes, Unset nat.vars: Yes, Resolve symlinks: Yes
. 2010-08-04 18:19:55.282 LS: ls -la, Ign LS warn: Yes, Scp1 Comp: No
. 2010-08-04 18:19:55.282 Local directory: default, Remote directory: home, Update: No, Cache: Yes
. 2010-08-04 18:19:55.282 Cache directory changes: Yes, Permanent: Yes
. 2010-08-04 18:19:55.282 DST mode: 1
. 2010-08-04 18:19:55.282 --------------------------------------------------------------------------
. 2010-08-04 18:19:55.364 Looking up host "xx.xx.xx.xx"
. 2010-08-04 18:19:55.364 Connecting to xx.xx.xx.xx port x
. 2010-08-04 18:19:55.437 Server version: SSH-2.0-OpenSSH_5.1p1 Debian-5
. 2010-08-04 18:19:55.437 We believe remote version has SSH-2 ignore bug
. 2010-08-04 18:19:55.437 Using SSH protocol version 2
. 2010-08-04 18:19:55.437 We claim version: SSH-2.0-WinSCP_release_4.2.8
. 2010-08-04 18:19:55.470 Doing Diffie-Hellman group exchange
. 2010-08-04 18:19:55.574 Doing Diffie-Hellman key exchange with hash SHA-1
. 2010-08-04 18:19:55.738 Host key fingerprint is:
. 2010-08-04 18:19:55.738 ssh-rsa 2048 xx:xx:xx:xx..............................
. 2010-08-04 18:19:55.738 Initialised AES-256 SDCTR client->server encryption
. 2010-08-04 18:19:55.738 Initialised HMAC-SHA1 client->server MAC algorithm
. 2010-08-04 18:19:55.738 Initialised AES-256 SDCTR server->client encryption
. 2010-08-04 18:19:55.738 Initialised HMAC-SHA1 server->client MAC algorithm
. 2010-08-04 18:19:55.837 Reading private key file "H:\ssh keys\root\root-key.ppk"
! 2010-08-04 18:19:55.838 Using username "root".
. 2010-08-04 18:19:55.875 Offered public key
. 2010-08-04 18:19:55.977 Offer of public key accepted
! 2010-08-04 18:19:55.978 Authenticating with public key "root-key"
. 2010-08-04 18:19:55.983 Prompt (2, SSH key passphrase, , Passphrase for key "root-key": )
! 2010-08-04 18:19:58.712 Access denied
. 2010-08-04 18:19:58.714 Access denied
. 2010-08-04 18:19:58.714 Disconnected: No supported authentication methods available
* 2010-08-04 18:19:58.717 (ESshFatal) Disconnected: No supported authentication methods available
* 2010-08-04 18:19:58.717 Anmeldungsprotokoll (Siehe Sitzungsprotokoll für Details):
* 2010-08-04 18:19:58.717 Verwende Benutzername "root".
* 2010-08-04 18:19:58.717 Authentifiziere mit öffentlichem Schlüssel "root-key".
* 2010-08-04 18:19:58.717 Zugriff verweigert.
* 2010-08-04 18:19:58.717 
* 2010-08-04 18:19:58.717 Anmeldung fehlgeschlagen.
kann man den ssh log auch direkt nach dem start bzw. restart von ssh in der console ausgeben? hab da irgendwann mal irgendwo was gelesen, aber google schweigt dazu leider :(...

ich hoffe wirklich das ihr mir weiterhelfen könnt, bitte!
Last edited by michi123 on 2010-08-04 18:33, edited 2 times in total.
User avatar
rudelgurke
Posts: 409
Joined: 2008-03-12 05:36
 

Re: winscp rootlogin und PermitRootLogin

Post by rudelgurke »

Stimmen Passphrase und Key den Winscp sendet ?
User avatar
Joe User
Project Manager
Project Manager
Posts: 11183
Joined: 2003-02-27 01:00
Location: Hamburg
 

Re: winscp rootlogin und PermitRootLogin

Post by Joe User »

SFTP per root möchte man nicht, dafür legt man sich passende User und Chroots an.

Eventuell hilft Folgendes:

Code: Select all

SubSystem internal-sftp
ForceCommand internal-sftp
Gegebenenfalls musst Du root noch ins Chroot stecken...
PayPal.Me/JoeUserFreeBSD Remote Installation
Wings for LifeWings for Life World Run

„If there’s more than one possible outcome of a job or task, and one
of those outcomes will result in disaster or an undesirable consequence,
then somebody will do it that way.“ -- Edward Aloysius Murphy Jr.
michi123
Posts: 73
Joined: 2010-08-04 17:45
 

Re: winscp rootlogin und PermitRootLogin

Post by michi123 »

yup, der key stimmt sicher überein - passphrase auch! ansonsten heult winscp schon rum wegen falschen key bzw. passphrase...

nachdem editieren der sshd_config bekomm ich nen error:

Code: Select all

/etc/ssh/sshd_config line 89: Missing subsystem command.
btw: hab das sshd loglevel von INFO auf VERBOSE gesetzt und bekomm nu folgende zeilen in der auth:

Code: Select all

sshd[14717]: Server listening on :: port x.
sshd[14717]: Server listening on 0.0.0.0 port x.
sshd[14723]: Connection from meine_ip port 52286
sshd[14723]: Found matching DSA key: FINGERPRINT
sshd[14723]: Found matching DSA key: FINGERPRINT
sshd[14723]: ROOT LOGIN REFUSED FROM meine_ip
sshd[14723]: Failed publickey for root from meine_ip port 52286 ssh2
irgendwo hackts da ;)...

aber egal, wie du schon gesagt hast, ich könnte ja auch mit nem user über sftp bzw. winscp verbinden! ich kann zwar gut mit der console umgehen, aber bequemer ist das bearbeiten von datein trotzdem über winscp :)). nur, wie lassen sich dann die datein bearbeiten, wenn ich zb. die apache configs bearbeiten möchte?? diese gehört root, und können auch nur von root geändert werden. muss der user mit dem ich über winscp arbeiten möchte, der gruppe root angehören? oder wie soll ich das machen?
root in eine chroot umgebung sperren horcht sich interessant an! hab heute auch schon einiges zu diesem thema gefunden. nur ist das nicht so wie bei den ftp usern, das dieser sich dann auch nur in den verzeichnissen (eben wo das chroot ist), bewegen kann?
User avatar
Joe User
Project Manager
Project Manager
Posts: 11183
Joined: 2003-02-27 01:00
Location: Hamburg
 

Re: winscp rootlogin und PermitRootLogin

Post by Joe User »

Zuerst http://www.minstrel.org.uk/papers/sftp/ und dann http://www.minstrel.org.uk/papers/sftp/builtin/ lesen/umsetzen (Pfade und Co ans eigene System anpassen!).
PayPal.Me/JoeUserFreeBSD Remote Installation
Wings for LifeWings for Life World Run

„If there’s more than one possible outcome of a job or task, and one
of those outcomes will result in disaster or an undesirable consequence,
then somebody will do it that way.“ -- Edward Aloysius Murphy Jr.
User avatar
rudelgurke
Posts: 409
Joined: 2008-03-12 05:36
 

Re: winscp rootlogin und PermitRootLogin

Post by rudelgurke »

Siehe letzte Zeile:

Failed publickey for root from meine_ip port 52286 ssh2

Sagt doch genau was das Problem ist.

Zum Subsystem:

Code: Select all

Subsystem sftp internal-sftp

Match user ...

ForceCommand internal-sftp
Und - nur generell - die Config Dateien die bearbeitet werden sollen sind nicht ohne Grund nur für "root" und die entsprechende Gruppe einsehbar - dass sollte auch so bleiben.
Vielleicht mal positiv sehen - je "umständlicher" desto umständlicher schleichen sich auch Fehler ein.

Und zum Chroot:

Code: Select all

Match user root
...
ChrootDirectory /root
...
Genau wie es in der Manpage steht und was man von Chroot erwartet.
michi123
Posts: 73
Joined: 2010-08-04 17:45
 

Re: winscp rootlogin und PermitRootLogin

Post by michi123 »

am schlüssel liegts definitiv nicht. hab das auch schon mit nem schlüssel von meinem normalen user versucht, mit dem ich mich ohne probs an der console bzw. winscp anmelden kann ;). also ist der fehler iwo anders vergraben.

hm, was meinste denn mit: "Sagt doch genau was das Problem ist." check ich net lol...

Code: Select all

Subsystem sftp internal-sftp

Match user ...

ForceCommand internal-sftp
so hab ichs gestern schon versucht ;) - bringt aber auch nix...

stimmt schon, einerseits sollte man die sicherheit nicht aus den augen lassen - andererseits sind wir ja alle ein bisschen faul :p

aber ist ja jetzt egal. nachdem ich im eigentlichen sinne eh gerne mit der console arbeite, hab ich auch kein problem damit - winscp nutzte ich bis vor kurzem immer nur zum bearbeiten von konfigurations-datein - weil das ist nicht so angenehm in der console. wenn man mal suchen&ersetzen braucht usw. dann kannste das in der console vergessen. und x will ich net!

wie gesagt, die man pages hab ich mir schon reingezogen. eine frage ist aber noch offen geblieben:
kann man das chroot NUR auf einen ordner beschränken? oder kann dieses auch mehrere ordner beinhalten?
ich möchte ftp komplett durch sftp ersetzen, und da wäre zb. für meinen www user nur ein directory (+subs) zu wenig.
der user sollte dann mindestens noch auf den backup ordner zugreifen können/dürfen (der sich in /var/backups/... befindet).
oder brauche ich dafür wieder einen extra user?

thx für die links :)!
und überhaupt, für eure hilfe :-BD
User avatar
Joe User
Project Manager
Project Manager
Posts: 11183
Joined: 2003-02-27 01:00
Location: Hamburg
 

Re: winscp rootlogin und PermitRootLogin

Post by Joe User »

Für "suchen+ersetzen" nimmt man einfach sed (Lesestoff) oder wenn man masochistisch veranlagt ist vi(m) ;)
Chroot akzeptiert nur einen Pfad, aber /var/backup kannst Du auch mit "mount --bind" ins Chroot mounten.
PayPal.Me/JoeUserFreeBSD Remote Installation
Wings for LifeWings for Life World Run

„If there’s more than one possible outcome of a job or task, and one
of those outcomes will result in disaster or an undesirable consequence,
then somebody will do it that way.“ -- Edward Aloysius Murphy Jr.