LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   Switching between root and user (https://www.linuxquestions.org/questions/slackware-14/switching-between-root-and-user-76223/)

PapaNoHair 07-26-2003 10:25 PM

Switching between root and user
 
I am running Slack 9.0 and I login at the command line. If I am in, say WindowMaker as user and desire to switch over to root (not su from command line) is there an easy way to switch over? Currently I am logging out, back to the prompt, then su to root, then reboot and reversing the process afterwards. There must be an easier way then this. Thanks in advance!:study:

jpbarto 07-27-2003 12:07 AM

why do you want to do as root that can't be done by 'su'ing at the command prompt?

Half_Elf 07-27-2003 12:29 AM

personnaly, want I need to do some task at root, without using SU (as example, renamming files on Fat32 partition I want to keep unwritable to users) I start a SECOND xfree session under root name. I mean I have both my users and root running each one an x.

slakmagik 07-27-2003 02:16 AM

I must be missing something. Why aren't either of you using 'su' in an xterm?

MasterC 07-27-2003 02:41 AM

Here's my take on the 2 things...

I push for more administration in a CLI. This does 2 things:
Keeps you from really jackin up your system so easily (you have to know the commands to use to do things)
Sorta forces you to get to learn what's actually going on behind the curtain, this will help for further diagnostics later sometimes.

However, many people who know CLI (and those that don't of course) will do things in a GUI for whatever reason. That's fine, and that's part of what's nice about linux is that you can, sometimes.

So if someone wants to be in root's gui everytime they use root to do something, or if they want to use a graphical tool that requires root priv's to run, that's great! The downside (other than that mentioned by Half_Elf) is that you have to logout and backin as root, then out as root and back in as user each time you want to. There are other ways, such as typing:
xhost +
first, but that's really work around and doesn't open up root's GUI.

So anyway, to expand on Half_Elf's suggestion:
Assuming you startx to get to your graphical environments, do this:
CTRL ALT F1
Login as user
startx
Then
CTRL ALT F2
Login as root
startx -- :1
And X for root will now be accessible by:
CTRL ALT F8
And X for user will be on
CRLT ALT F7

HTH

Cool

<PS>
There is also, sudo which is highly recommended even over su AFAIK.
</PS>

Half_Elf 07-27-2003 08:34 AM

Quote:

So anyway, to expand on Half_Elf's suggestion: Assuming you startx to get to your graphical environments, do this:
my personnal script is better, try this instead :
First rename "/usr/X11/bin/startx" as "/usr/X11/bin/start"
then create "startx" and write this script in it :

Code:

#!/bin/sh

if [ $# -eq 0 ]      # check to see if arguements are given (color depth)
      then a=24    # default color depth
        else a=$1    # use given color depth
fi

if [ $a -ne 8 -a $a -ne 16 -a $a -ne 24 ]
        then
                echo "Invalid color depth. Use 8, 16, or 24."
        exit 1
fi

for display in 0 1 2 3 4 5    # checks for open display, starts X on next available
        {
        if [ ! -f "/tmp/.X$display-lock" ]
                then
                    `start -- :$display -depth $a 1>/tmp/X$display.log 2>/tmp/X$display.log &`
                exit 0;
        fi
        }
echo "No displays available."
exit 1

Then make sure the script (the new "startx") is executable (type chmod +x) and create X1.log, X2.log, X3.log, X4.log X5.log and X6.log in /tmp.

This little script allow you to start up to 6 X sessions and save it's log in a files so you don't loose your terminal.

Anyways have fun :)

Tuttle 07-27-2003 10:30 AM

Very usefull, thanks people!

PapaNoHair 07-27-2003 11:52 AM

Switching between root and user
 
Quote:

Originally posted by MasterC
Here's my take on the 2 things...

I push for more administration in a CLI. This does 2 things:
Keeps you from really jackin up your system so easily (you have to know the commands to use to do things)
Sorta forces you to get to learn what's actually going on behind the curtain, this will help for further diagnostics later sometimes.

However, many people who know CLI (and those that don't of course) will do things in a GUI for whatever reason. That's fine, and that's part of what's nice about linux is that you can, sometimes.

So if someone wants to be in root's gui everytime they use root to do something, or if they want to use a graphical tool that requires root priv's to run, that's great! The downside (other than that mentioned by Half_Elf) is that you have to logout and backin as root, then out as root and back in as user each time you want to. There are other ways, such as typing:
xhost +
first, but that's really work around and doesn't open up root's GUI.

So anyway, to expand on Half_Elf's suggestion:
Assuming you startx to get to your graphical environments, do this:
CTRL ALT F1
Login as user
startx
Then
CTRL ALT F2
Login as root
startx -- :1
And X for root will now be accessible by:
CTRL ALT F8
And X for user will be on
CRLT ALT F7

HTH

Cool

<PS>
There is also, sudo which is highly recommended even over su AFAIK.
</PS>

Thanks very much to all of you - I learned a lot! To answer those about su'ing into cli: I have found some things that just do not seem to work unless I am logged in as root. Plus even though I use the cli more frequently than I would have thought a year or two ago, I still like the graphic interface. Thanks again!:D

Half_Elf 07-27-2003 04:27 PM

Quote:

I have found some things that just do not seem to work unless I am logged in as root.
Just make sure it's not a configuration problem 'bout these "things". You should never run anything at root under linux (but I agree some apps are badly made and you need to run them as root anyways).

If you use KDE, there's an option in property to "run as different user". It is probably safer to run a single program at root than all an X. Just right click on a program icon and select property (the same things exist in gnome I believe).

You may also want to know that it is possible to set a bit of permission to an executable to give the possibility to anyone to run it as a different user. Search about setuid and setgid (the first one tell that the program will run under owner name and the second, under group name. This is especially usefull for safe application that require a root right (like cdrecord and all burn cdrom apps).

itsjustme 07-27-2003 10:02 PM

Re: Switching between root and user
 
Quote:

Originally posted by PapaNoHair
I have found some things that just do not seem to work unless I am logged in as root.
Is that also true if you do 'su -' from the command line, as opposed to just 'su'?

Locura 07-27-2003 11:22 PM

Quote:

Originally posted by Half_Elf
personnaly, want I need to do some task at root, without using SU (as example, renamming files on Fat32 partition I want to keep unwritable to users) I start a SECOND xfree session under root name. I mean I have both my users and root running each one an x.
There is simply no reason to EVER do that. Rename them via the CLI from a terminal, using su to become root.

Half_Elf 07-28-2003 07:38 AM

Quote:

There is simply no reason to EVER do that. Rename them via the CLI from a terminal, using su to become root.
Have you ever tried to rename 300 Mp3s that are all in the same folder? It's a damn pain in terminal!!!

And I often start a second X when I want to use wine to run some progs on my fat32 partition. First, my users can't write on my fat32 partition (and I wish to keep it like this), second wine is a beta progs, meaning there's some strange bugs, like it has some problem resizing windows. Mean that if I start something in my 1280x1024 resolution, wine will only use a small square of 640x480. Ugly. And don't tell me my wine config isn't good I have tried a lot of things, if wine start the progs in full screen, it creates different problems.

yes, there is EVER reasons to do that. and ANYWAYS it's not really dangerous to start an X at root, X isn't a major vulnerability, especially when it doesn't listen for external connection.

PapaNoHair 07-28-2003 09:53 AM

Re: Re: Switching between root and user
 
Quote:

Originally posted by itsjustme
Is that also true if you do 'su -' fom the command line, as opposed to just 'su'?
Hmmm - haven't tried it that way (su -); pardon my ignorance but what is the difference?

Noryungi 07-28-2003 10:25 AM

The difference between "su -" and "su" is, probably, that one will give you a "fully root" command line (with the options defined for user "root"), while the other will retain the options of the user entering "su".

Can't remember which is which, though... I use sudo myself... :D

itsjustme 07-28-2003 12:58 PM

This is from the rute manual.

Quote:

11.7.2 The set user, su command

To temporarily become another user, you can use the su program:

su jack

This command prompts you for a password (unless you are the root user to begin with). It does nothing more than change the current user to have the access rights of jack. Most environment variables will remain the same. The HOME, LOGNAME, and USER environment variables will be set to jack, but all other environment variables will be inherited. su is, therefore, not the same as a normal login.

To get the equivalent of a login with su, run

su - jack


This will cause all initialization scripts (that are normally run when the user logs in) to be executed. [What actually happens is that the subsequent shell is started with a - in front of the zero'th argument. This makes the shell read the user's personal profile. The login command also does this.] Hence, after running su with the - option, you logged in as if with the login command.
And if you don't specify a username, then 'root' is assumed, for 'su -'.

regards...


All times are GMT -5. The time now is 03:42 PM.