1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

set bash by default?

Discussion in 'Tomato Firmware' started by maurer, Jun 26, 2012.

  1. maurer

    maurer LI Guru Member

    hi,

    can you help me set bash as default when i login by ssh?

    shibby 093 on my RT-N16
    1GB usb drive mounted as /opt
     
  2. ulyan

    ulyan Networkin' Nut Member

    + 1. Though I don't know if it is even possible. You can use it like this.
    Code:
    bash -c [command]
    where command is something like ls, cat etc.
     
  3. koitsu

    koitsu Network Guru Member

    There is no true bash shell on Tomato, TomatoUSB, etc.. The only way to get it is to install it via ipkg, and the bash binary there is extremely old. You could also download the version from here but that doesn't solve the issue of the default shell still being /bin/sh (Busybox's bash-like shell, which is atrocious and horrible).

    There are two solutions as I see them:

    1. Put "exec /path/to/bash" in /root/.profile. However, this has potential infinite loop situations, depending on how a sub-shell (within a script, etc.) is spawned, and as such I do not recommend it.

    2. Execute the following:

    Code:
    sed -i -e 's#/root:/bin/sh$#/root:/path/to/bash#' /etc/passwd
    
    Neither of the above solutions are retained after a reboot. Thus, you would need to put, for example, the #2 solution in Admin -> Scripts -> Init.

    Be aware however that /path/to/bash needs to always exist. Let's say you use /opt/bin/bash instead, and /opt happens to be a CIFS mount (from a Windows box or other machine on your LAN). Let's say that that machine is down when you attempt to log in to the router -- you will end up with a hung telnet/ssh session, or possibly receive nasty errors. In this case you are absolutely screwed until wherever your bash binary exists is made available again (e.g. CIFS share becomes available).

    So overall, there is no good absolute clean and 100% failsafe way to do what you want. Honestly if you're going to be using the CLI this much, you should consider switching to OpenWRT, where packages and binaries and shells are all well-maintained and there is none of this hackery going on.
     
  4. maurer

    maurer LI Guru Member

    thanks for your reply,

    only no.1 solution worked
    with no2 i cannot login with my user/pass unless in change back to /bin/sh

    as for openwrt, as you see in my signature - i'm a big fan.
    RT-N16 support in openwrt is not yet completed - i already tried it but i'm not happy with some facts like wifi limited to 20mhz channel (144mbps raw)
     
  5. koitsu

    koitsu Network Guru Member

    telnet works fine with the 2nd method I listed. Validation:

    Code:
    $ telnet gw
    Trying 192.168.1.1...
    Connected to gw.home.lan.
    Escape character is '^]'.
    gw login: root
    Password:
     
    Tomato v1.28.0499 MIPSR2Toastman-RT-N K26 USB VPN
    root@gw:/tmp/home/root# sed -i -e 's#/root:/bin/sh$#/root:/opt/bin/bash#' /etc/passwd
    root@gw:/tmp/home/root# grep root /etc/passwd
    root:x:0:0:root:/root:/opt/bin/bash
    root@gw:/tmp/home/root#
    
    Then in another window:

    Code:
    $ telnet gw
    Trying 192.168.1.1...
    Connected to gw.home.lan.
    Escape character is '^]'.
    gw login: root
    Password:
     
    Tomato v1.28.0499 MIPSR2Toastman-RT-N K26 USB VPN
    root@gw:~# echo $BASH_VERSION
    4.1.0(1)-release
    
    Note the prompt difference as well, in case $BASH_VERSION isn't enough proof.

    I can test with SSH if need be, but I know that the sshd on TomatoUSB (I think that's Dropbear?) is extremely finicky; as such I tend to just use telnet and never enable sshd.

    But again: I strongly urge you not to use the first method I listed. It absolutely could result in an infinite loop in very specific circumstances (sub-shells spawned); it'd be the equivalent of a fork bomb, except since exec is used (which replaces the existing running process), you'd simply have an infinite loop of "exec bash" occurring.

    Though if you are using SSH, hopefully Dropbear supports running commands when issued via an SSH client. E.g. "ssh 192.168.1.1 ls -l". If it does, then you could simply make your SSH client do the equivalent of: "ssh 192.168.1.1 exec /path/to/bash", that way the problem with #1 is solved entirely. This can be accomplished in clients such as PuTTY as well (see Connection -> SSH -> Remote command).

    I would absolutely love for Busybox to be completely and entirely removed from TomatoUSB. It's such a pile of shit, and I'm being nice by saying that. It's so utterly broken in so many ways; I've written patches for it too many times over the years and the breakage never ends. It would honestly be wonderful to have native utilities and not half-ass ones. And please don't tell me that ipkg and /opt stuff is sufficient, because it's not -- the default $PATH on TomatoUSB has /opt paths at the end of $PATH, not at the start, thus overriding built-in utilities is virtually impossible. and I understand that's intentional and why it's intentional, which further justifies the need to scrap Busybox entirely, IMO.
     
  6. Aditaa

    Aditaa Serious Server Member


    If you use option #2 you can make it permanent if you execute:
    Code:
    nvram setfile2nvram /etc/passwd
    nvram commit
    
    PLEASE NOTE::
    This is dangerous if you do not do this step rebooting your router would erase these setting ( possibly fixing any mistakes ie /path/to/bash location wrong or /opt removed )
    After this it is permanent ... you can possibly lock your self out of root access to the device ... needing to re-flash to correct
     

Share This Page