WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Now 'sudo su' in /root  (Read 24216 times)

Offline hjkl

  • Newbie
  • *
  • Posts: 23
Now 'sudo su' in /root
« on: December 14, 2008, 06:01:08 PM »
Hi,

b34a6ad48638bd082727c8053923d5c9  tinycore_1.0rc4.iso

I open a terminal on TinyCore and 'sudo su'.  Now, I get "root@box:~#" and become a root user
in "/root".  Before the change, 'sudo su' gave me "root@box:/home/tc#" and used "/home/tc" directory.
I know this is not a bug because I also noticed a change in JWM's menu.

From the menu:

(new: root@box:~#)
aterm -cr red -T "Root Shell" -e sudo su

(old: root@box:/home/tc#)
aterm -cr red -T "Root Shell" -e sudo /bin/sh

I got used to the "old" behavior, so I would like to know why this change is better
than the other one.

Offline tobiaus

  • Suspended
  • Hero Member
  • *****
  • Posts: 599
Re: Now 'sudo su' in /root
« Reply #1 on: December 14, 2008, 06:58:44 PM »
both are home directories, it's the same as cd ~ ... /home/tc is user tc's home, /root is user root's home.

it makes less sense if you are root to be in another user's home directory.

Offline hjkl

  • Newbie
  • *
  • Posts: 23
Re: Now 'sudo su' in /root
« Reply #2 on: December 14, 2008, 08:41:18 PM »
Hi tobiaus,

I see what you mean.  Then, I wonder why we kept the other way for a long time.
If I am not mistaken, the "old" behavior goes back beyond DSL-2.0.
Well, I think I have to get rid of my old habit.

Thanks for the reply.

Offline ^thehatsrule^

  • Retired Admins
  • Hero Member
  • *****
  • Posts: 1726
Re: Now 'sudo su' in /root
« Reply #3 on: December 14, 2008, 11:05:01 PM »
hjkl: I agree with your first post.

`sudo su` should not change dirs because it should retain most of the calling user's environment (unless it was made to do so explicitly, ie in sudoers, or a login shell).  I'm not sure what change caused this.

I was comparing 1.0 rc3 and rc4 and did not notice a difference between the jwm menus though (~/.jwmrc)

Offline mikshaw

  • Sr. Member
  • ****
  • Posts: 368
Re: Now 'sudo su' in /root
« Reply #4 on: December 15, 2008, 07:59:43 AM »
As I see it, using su from within an existing  terminal should never change the directory, and shouldn't change the environment unless you do "su -".  Maybe that's not how su was officially designed, but that's what I think it was designed to do, and that's what makes sense to me.

Quote
(new: root@box:~#)
aterm -cr red -T "Root Shell" -e sudo su

(old: root@box:/home/tc#)
aterm -cr red -T "Root Shell" -e sudo /bin/sh

I got used to the "old" behavior, so I would like to know why this change is better
than the other one.

The above change is partly logical to me.  Opening a root shell from a menu item should use the root user's chosen shell.  The old version used /bin/sh regardless of what root's shell happens to be (assume the shell may have been changed to bash or zsh or whatever else).

I'm not so sure about " root@box:~#".  I don't have a problem with it, but I don't understand why or how the root shell is opening in /root.  Typically a new shell opens within whatever directory  you were in when you opened it, regardless of what HOME is.
« Last Edit: December 15, 2008, 08:01:29 AM by mikshaw »

Offline tobiaus

  • Suspended
  • Hero Member
  • *****
  • Posts: 599
Re: Now 'sudo su' in /root
« Reply #5 on: December 15, 2008, 05:23:17 PM »
Typically a new shell opens within whatever directory  you were in when you opened it, regardless of what HOME is.

i agree with you, if we're talking about the same tty or the same aterm, switching from user to root and root to user. (although i've seen distros that do not behave this way.)

at any rate it matters more to me (and even then not too much) that the home folder be opened to per new tty or per aterm opened than whether or not sudo su follows that.

in linux there are few standards, but there are many conventions. certainly doing it the dsl way makes perfect sense, unless there is very good reason or strong preference to the contrary.

Offline mikshaw

  • Sr. Member
  • ****
  • Posts: 368
Re: Now 'sudo su' in /root
« Reply #6 on: December 15, 2008, 11:45:26 PM »
Quote
i agree with you, if we're talking about the same tty or the same aterm, switching from user to root and root to user.
Yes, and I would expect a  menu item to behave the same.  If, for example, you were to cd to an arbitrary directory while in tty , and then startx, you are still now in that new directory, and not in HOME.  If you then start a terminal, either regular or root, I would think it would start off in that new directory.  As I said, though, I don't have a problem with this particular situation being changed, as you said there are varying conventions...I guess either way works.  What I haven't understood is *how* this is done.  There doesn't seem to be anything that explicitly sends root to his home when a root term is opened.

Offline ^thehatsrule^

  • Retired Admins
  • Hero Member
  • *****
  • Posts: 1726
Re: Now 'sudo su' in /root
« Reply #7 on: December 16, 2008, 12:43:00 AM »
I guess the only way would be to manually check the differences between rc3 and rc4... unless someone has some kind of insight into this change.

Offline ke4nt

  • Retired Admins
  • Jr. Member
  • *****
  • Posts: 79
Re: Now 'sudo su' in /root
« Reply #8 on: December 16, 2008, 01:15:43 AM »
In other distros I dabble in, it was my understanding that if I use "sudo su" , I would still have
the global path of the user that I was before using the command, and somewhat limited use of the root shell
due to differing .bash profiles.

If I use " sudo su - " ( or su - )  , then i get the full root path, and unlimited use of the shell.

Is this incorrect?  Not the usual behavior?

73
ke4nt
....The CORE Lives....

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14815
Re: Now 'sudo su' in /root
« Reply #9 on: December 16, 2008, 01:20:10 AM »
isn't it "su -l" rather than "su -"?

Offline roberts

  • Retired Admins
  • Hero Member
  • *****
  • Posts: 7361
  • Founder Emeritus
Re: Now 'sudo su' in /root
« Reply #10 on: December 16, 2008, 01:29:53 AM »
I guess the only way would be to manually check the differences between rc3 and rc4... unless someone has some kind of insight into this change.
Updated busybox which controls login and shell
10+ Years Contributing to Linux Open Source Projects.

Offline ^thehatsrule^

  • Retired Admins
  • Hero Member
  • *****
  • Posts: 1726
Re: Now 'sudo su' in /root
« Reply #11 on: December 16, 2008, 01:33:00 AM »
Juanito: either or.  - is just shorter

I guess there's always su -p (though still a bit different)

ah, I forgot su was part of bb.

Offline hjkl

  • Newbie
  • *
  • Posts: 23
Re: Now 'sudo su' in /root
« Reply #12 on: December 16, 2008, 11:59:14 AM »
Hi,
Thanks everyone for good insights.  They help.

To ^thehatsrule^:
Quote
I was comparing 1.0 rc3 and rc4 and did not notice a difference between the jwm menus though (~/.jwmrc)
You are correct.  I forgot about the fact that the command:

aterm -cr red -T "Root Shell" -e sudo /bin/sh

was something I remembered.
Coincidentally, that line produced something I would want to see and made me jump to the conclusion.
There is nothing to do with JWM's menu.

To mikshaw:
Quote
The above change is partly logical to me.  Opening a root shell from a menu item should use the root user's chosen shell.  The old version used /bin/sh regardless of what root's shell happens to be (assume the shell may have been changed to bash or zsh or whatever else).
Again, you are right.  That was my mistake.  Thank you for the information.
Quote
I guess either way works.  What I haven't understood is *how* this is done.  There doesn't seem to be anything that explicitly sends root to his home when a root term is opened.
That's exactly what I would like to know.

To roberts:
Quote
Updated busybox which controls login and shell
I need to spend more time studying BusyBox.
OT:
Thank you very much for TinyCore.  This is a very exciting project.  I like it a lot.

Offline hjkl

  • Newbie
  • *
  • Posts: 23
Re: Now 'sudo su' in /root
« Reply #13 on: December 30, 2008, 12:37:46 AM »
Hi,

I have been using BusyBox's 'su' that comes with TinyCore.
So, when I 'sudo su' in '/home/tc', I become 'root' in '/root' directory.
 tc@box:~$ sudo su
 root@box:~#

Let's suppose that I'm a 'root' user, but a 'tc' user is a different person.
Then, I have no business using the 'tc' user's account or shell environment.
So, the "default" behavior of 'sudo su' on TinyCore makes sense.

However in my case, I am the 'root' and 'tc' user.  I am the only person using my computer.
Also, being able to use the 'tc' user's configuration files as 'root' is very practical.
Therefore, I would like to have choices of using the "default" behavior or
sharing the 'tc' user's shell account and its environment.
My solution is to replace BusyBox's 'su' with 'su' from GNU Coreutils.

** Warning: This will install 'su' on your TinyCore temporally. **

24a7ab466c9b448203b9b2f7be944c4d  tinycore_1.0rc8.iso

0e718639040e05ca7a3822f1a7d1163e  compiletc.tce
 tc@box:~$ tce-load compiletc.tce

94e5558ee2a65723d4840bfde2d323f0  coreutils-5.0.tar.bz2
 tc@box:~$ tar -xvjf coreutils-5.0.tar.bz2
 tc@box:~$ cd coreutils-5.0
 tc@box:~/coreutils-5.0$ ./configure
 tc@box:~/coreutils-5.0$ make
 tc@box:~/coreutils-5.0$ sudo cp src/su /bin
 tc@box:~/coreutils-5.0$ exit

Now, when I 'sudo su' in '/home/tc', I become 'root' and stay in the same directory.
However, the 'tc' user's shell account and its environment are not kept.
 tc@box:~$ sudo su
 root@box:/home/tc#

When I want to share the environment, I use 'sudo su -m' or 'sudo su -p'.
I hope this works for you too.

Offline mikshaw

  • Sr. Member
  • ****
  • Posts: 368
Re: Now 'sudo su' in /root
« Reply #14 on: December 30, 2008, 09:03:12 AM »
Quote
Let's suppose that I'm a 'root' user, but a 'tc' user is a different person.
Then, I have no business using the 'tc' user's account or shell environment.
So, the "default" behavior of 'sudo su' on TinyCore makes sense.
I disagree, since "sudo su" isn't the way for multiple people to use a system.
Tiny Core itself isn't configured by default to be a typical multiuser system.
I would say if you wanted to do this, you'd be better to make a couple of changes
to the init process and give each user a login prompt.

Quote
Now, when I 'sudo su' in '/home/tc', I become 'root' and stay in the same directory.
However, the 'tc' user's shell account and its environment are not kept.
 tc@box:~$ sudo su
 root@box:/home/tc#

When I want to share the environment, I use 'sudo su -m' or 'sudo su -p'.
I agree that this is the way  it *should* be, since the user should have the choice and control of such behavior. But as I said it isn't a big problem for me.  The one place where it would be a serious pain (and which I haven't tried) is in compiling software.  I typically configure and make as regular user, except in a few instances where proper building doesn't happen without root power.  When it comes to "make install", I'll sudo su and still be in that same directory.  Whether or not "sudo make install" would be a suitable alternative, i don't know.  Personally  would like to remove sudo entirely (its reason for existence is to make things easier in a multi-user system) and stick with su only.   But that's going a little off-topic.