root locked out on CLI due to login shell problem

Any questions about the Command Line Interface can be placed here!
Forum rules
Please note the disclaimer before modifying your Synology Product.

root locked out on CLI due to login shell problem

Postby st3623 » Sat Jul 14, 2012 11:53 am

Hi all,

I'm out of ideas on how to regain root SSH access to my DS1511+ after an upgrade to DSM 4.0 and a subsequent attempt to reinstall ipkg.

Here is what happened:
- Under DSM 3.2 I had installed a number of ipkg packages, one of them being zsh. Unfortunately (now I know better) I have changed the root login shell to `/opt/bin/zsh` without creating a backup user with id 0.
- After the upgrade to DSM 4.0 I wanted to reinstall all my ipkg stuff from scratch and cleared out everything in /opt.
- I logged out.

Current status:
- I can't (SSH) login as root anymore, SSH always errors out with `/opt/bin/zsh: No such file or directory`.
- I can ssh in with the `admin` account, but since it doesn't have write access to most parts of the filesystem it's not of much use (still, I have read access to almost everything).
- The rest of the system is running nicely.

What I tried so far:
- ssh in as `admin` and `su <something>`: doesn't work since busybox cannot run su from a non-root account.
- `ssh root@host /bin/ash` doesn't work, since SSH still errors out with `/opt/bin/zsh: No such file or directory`.
- `scp fixedfile root@host:/etc/passwd` also fails with the same error.

Questions:
- Is there some known way to use the DSM web interface to fix `/etc/passwd` ?
- If there is no way to regain root SSH access without reinstalling the system, how do I best go about it with minimal reconfiguration effort and, of course, without loosing the contents of my data disks?

I'm seriously looking forward to any help on this...

Cheers,
Mathias
st3623
I'm New!
I'm New!
 
Posts: 2
Joined: Sat Jul 14, 2012 11:32 am

Re: root locked out on CLI due to login shell problem

Postby maxxfi » Sat Jul 14, 2012 2:36 pm

Try to force a reinstallation of DSM 4.0 (or try 4.1 beta :wink:).
It should reset the /etc/passwd
DS-411 (DSM 4.2-3202) w/ 2x WD10EFRX + 1x HD154UI
DS-106j (DSM 3.0-1357), PATA-to-SATA adapter, 2.5" HM250HI
User avatar
maxxfi
Architect
Architect
 
Posts: 4425
Joined: Sun Dec 27, 2009 12:13 pm
Location: Espoo, Finland

Re: root locked out on CLI due to login shell problem

Postby st3623 » Sat Jul 14, 2012 5:34 pm

Ok, problem fixed.

The solution was to use a custom .pat "firmware update" file.
Even though more than 4 years old the info [on this page]http://oinkzwurgl.org/diskstation_patchfiles is still current, it works nicely even for DSM 4.0.

What I did:
- download the syno-universal-pat_20080227.tar.gz template
- add one line to file "updater2": sed -i -e "s/opt\/bin\/zsh/bin\/ash/" /etc/passwd
- repackage into a .pat file
- upload and run via the web interface

The script runs through nicely, as the root user.
So, if anybody should shut themselves out: with a custom .pat file you can do pretty much anything.

Cheers,
Mathias
st3623
I'm New!
I'm New!
 
Posts: 2
Joined: Sat Jul 14, 2012 11:32 am

Re: root locked out on CLI due to login shell problem

Postby CoolRaoul » Sat Jul 14, 2012 7:54 pm

It's a bad and risky idea to change root default shell

One alternative (and IMHO safer) solution would be to add the following code at the beginning of root's profile (/root/.profile), providing the same results without any potential damage

Code: Select all
if [ "$ZSH_VERSION" = "" ] ;then
    case $- in
        # only for interactive shells
        # (just to be safe but not really needed)
        *i*)
            echo >&2 "exec'ing zsh"
            exec zsh --login
            ;;
    esac
fi
CR
CoolRaoul
Sharp
Sharp
 
Posts: 162
Joined: Tue May 18, 2010 7:08 pm

Re: root locked out on CLI due to login shell problem

Postby maxxfi » Sat Jul 14, 2012 8:10 pm

I fully agree with previous solution, but before the "exec zsh --login", I would suggest also to test if zsh is present.
I used to believe that 'exec' is able to verify it itself, but it seems to me that the Synology/busybox version doesn't perform any checks.
DS-411 (DSM 4.2-3202) w/ 2x WD10EFRX + 1x HD154UI
DS-106j (DSM 3.0-1357), PATA-to-SATA adapter, 2.5" HM250HI
User avatar
maxxfi
Architect
Architect
 
Posts: 4425
Joined: Sun Dec 27, 2009 12:13 pm
Location: Espoo, Finland

Re: root locked out on CLI due to login shell problem

Postby CoolRaoul » Sat Jul 14, 2012 10:10 pm

maxxfi wrote:before the "exec zsh --login", I would suggest also to test if zsh is present

Right,
To do this, simply replace 1st line with:

Code: Select all
if [ "$ZSH_VERSION" = "" ] && which zsh >/dev/null 2>&1 ; then
CR
CoolRaoul
Sharp
Sharp
 
Posts: 162
Joined: Tue May 18, 2010 7:08 pm

Re: root locked out on CLI due to login shell problem

Postby norrellmeister » Sun Jul 29, 2012 4:43 am

I had this exact problem. Managed to fix it by installing a package called "config file editor", through the web UI, and using that to edit /etc/passwd. Another thing to keep in mind is that, if you have it set up, you may be able to fix this by editing /etc/passwd through SCP.
norrellmeister
I'm New!
I'm New!
 
Posts: 8
Joined: Sat Sep 17, 2011 7:37 pm


Return to Command Line Interface

Who is online

Users browsing this forum: No registered users and 1 guest