Kein ssh-login auf MyBookLive mehr [gelöst]
In meinem Backup-Script sichere ich seit langer Zeit meine Daten auf mybooklive.fritz.box (das ist mein NAS). Von einem Tag auf den anderen funktioniert das Script nicht mehr.
Kurzfassung der Lösung
- in der Datei /etc/ssh/sshd_config auf MyBookLive fehlten die AllowUsers
AllowUsers root wnf bine
- Das Home-Verzeichnis des Users wnf gehörte nicht mehr wnf sondern nobody
# chown wnf:share /shares/wnf
Woran kann das liegen?
Der Ping funktioniert
$ ping mybooklive.fritz.box PING mybooklive.fritz.box (192.168.1.6) 56(84) bytes of data. 64 bytes from mybooklive (192.168.1.6): icmp_req=1 ttl=64 time=0.197 ms $ ping mybooklive.local PING mybooklive.local (192.168.1.6) 56(84) bytes of data. 64 bytes from mybooklive (192.168.1.6): icmp_req=1 ttl=64 time=0.161 ms $ ping mybooklive PING mybooklive (192.168.1.6) 56(84) bytes of data.
Jetzt versuche ich mich per ssh auf MyBookLive anzumelden.
$ ssh root@mybooklive.fritz.box @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY! Someone could be eavesdropping on you right now (man-in-the-middle attack)! It is also possible that a host key has just been changed. The fingerprint for the RSA key sent by the remote host is 37:75:0e:15:12:78:30:55:11:fb:9b:aa:21:b4:df:05. Please contact your system administrator. Add correct host key in /home/wnf/.ssh/known_hosts to get rid of this message. Offending RSA key in /home/wnf/.ssh/known_hosts:7 remove with: ssh-keygen -f "/home/wnf/.ssh/known_hosts" -R mybooklive.fritz.box RSA host key for mybooklive.fritz.box has changed and you have requested strict checking. Host key verification failed.
Ja, wenn der ssh-Zugriff auf MyBookLive nicht mehr funktioniert, dann kann die Datensicherung natürlich auch nicht mehr funktionieren.
Also wie angegeben den alten Schlüssel entfernen:
$ ssh-keygen -f "/home/wnf/.ssh/known_hosts" -R mybooklive.fritz.box /home/wnf/.ssh/known_hosts updated. Original contents retained as /home/wnf/.ssh/known_hosts.old
Und dann beim Anmelden per ssh wieder herstellen:
wnf@c2012:~$ ssh root@mybooklive.fritz.box The authenticity of host 'mybooklive.fritz.box (192.168.1.6)' can't be established. RSA key fingerprint is 37:75:0e:15:12:78:30:55:11:fb:9b:aa:21:b4:df:05. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'mybooklive.fritz.box' (RSA) to the list of known hosts. Warning: the RSA host key for 'mybooklive.fritz.box' differs from the key for the IP address '192.168.1.6' Offending key for IP in /home/wnf/.ssh/known_hosts:4 Are you sure you want to continue connecting (yes/no)? yes root@mybooklive.fritz.box's password:
Als normaler User kann ich mich immer noch nicht anmelden. Bei der Kontrolle der Datei /etc/ssh/sshd_config auf MyBookLive fiel mir auf, dass in der Zeile
AllowUsers root
die anderen Benutzer fehlten
AllowUsers root wnf bine
außerdem
#AuthorizedKeysFile %h/.ssh/authorized_keys
ändern in
AuthorizedKeysFile %h/.ssh/authorized_keys
Also die Datei bearbeiten und vom sshd neu einlesen lassen:
# nano /etc/ssh/sshd_config MyBookLive:/# /etc/init.d/ssh reload
Und es funktioniert immer noch kein Einloggen ohne Passwort.
Deshalb als root auf mybooklive einloggen und die Meldungen aus /var/log/sshd.log anzeigen:
# egrep -i 'ssh.*wnf' /var/log/sshd.log May 3 15:02:59 MyBookLive sshd[7320]: Authentication refused: bad ownership or modes for directory /shares/wnf May 3 15:02:59 MyBookLive sshd[7320]: Authentication refused: bad ownership or modes for directory /shares/wnf
Kontrolle wer das Homeverzeichnis besitzt:
# ls -l /shares/ drwxr-xr-x 17 nobody share 65536 Aug 26 2013 wnf
# chown wnf:share /shares/wnf # ls -l /shares/ drwxr-xr-x 17 wnf share 65536 Aug 26 2013 wnf
Und siehe da es funktioniert der passwort-lose zugriff auf mein NAS MyBookLive wieder.
Neuer Rechner neues Glück.
Das anmelden per ssh funktioniert nur per Passwort-Authentifizierung.
$ ssh-copy-id -i ~/.ssh/id_rsa.pub bine@mybooklive Warning: the RSA host key for 'mybooklive' differs from the key for the IP address '192.168.1.6' Offending key for IP in /home/bine/.ssh/known_hosts:3 Matching host key in /home/bine/.ssh/known_hosts:5 Are you sure you want to continue connecting (yes/no)? yes bine@mybooklive's password: sh: line 2: .ssh/authorized_keys: Keine Berechtigung
Login auf MyBookLive und dort die .ssh/authorized_keys löschen
rm .ssh/authorized_keys
wieder ausloggen und den Schlüssel erneut übertragen:
$ ssh-copy-id -i ~/.ssh/id_rsa.pub bine@mybooklive /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys bine@mybooklive's password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh 'bine@mybooklive'" and check to make sure that only the key(s) you wanted were added. $ ssh mybooklive