What's new
  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

How should I modify the root login shell?

dpyro

New Around Here
I'm trying to change the root login shell to become /opt/bin/bash or /opt/bin/zsh. Since /etc/passwd and /etc/groups are being pulled from the firmware, and there is no usermod type utility that I can see to do it,

The only thing I can think of is doing a sed or awk on /etc/passwd to do this. Additionally, how do I let it fallback to /bin/sh if say I my /opt partition fails (being on a USB drive and all)? I'm thinking /jffs/scripts/services-start:

Code:
#!/bin/sh

# Replace root shell
ROOT_SHELL=/opt/bin/bash
[ -x $ROOT_SHELL ] && awk -F: "{sub(/\root:\/bin\/sh/,\"$ROOT_SHELL\"); print;}" /etc/passwd

Any better or possibly safer way to do this? I really don't like poking at the root login :(

Note: Tested the code in sh and busybox awk, but not the script.
 
You could try mount binding the replacement shell on top of the Busybox one. Not sure if that will work since it's currently a symlink to Busybox, but give it a try:

Code:
mount -o bind /opt/bin/bash /bin/sh

If it fails, just reboot the router to revert the change. If it works, then you could put it in a startup script.
 

Similar threads

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Back
Top