Solved

switch betwen root and user  accounts on linux once login root account  already

Posted on 2014-09-10
5
445 Views
Last Modified: 2014-09-14
Dear Experts,

Every time, when I'm using my VPS root account on linux shell, and then
I go to other user accounts, I will type # su otherusers, and then type exit go back to
root shell after typing password again. Is there any keyword/command  I can switch both root and user account without re-type su, type password ,type exit if I will do it many times  and without creating too many putty remote shell so that get less  error on less typing ?

Please advise

Rwiceing
0
Comment
Question by:rwniceing
  • 2
  • 2
5 Comments
 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 250 total points
ID: 40314423
To run a command as "otheruser" from root you can simply issue

su otheruser -c command

The non-root shell will terminate once "command" has completed, so there will be no need for "exit". root will not be asked for the password of "otheruser". If you need the environment set for "otheruser" add a hyphen to the "su" command call:

su - otheruser -c command

"su [-] otheruser -c" can be set as an alias ("less typing"):

alias as_otheruser="su - otheruser -c "

as_otheruser command

will now do the trick.

Likewise, you can run commands requiring root privileges from "otheruser" by means of "sudo" and appropriate entries in the "sudoers" file. There is an option in "sudoers" to avoid being prompted for passwords.

Log in directly as "otheruser" and run root commands like this:

sudo command_on_behalf_of_root

Frequently used sudo root commands can also be aliased, of course.

You can use "sudo" to run commands on behalf of other non-root users (if so configured):

From "otheruser":

sudo -u otheruser2 command_on_behalf_of_otheruser2

Finally, sudo can be used to start an interactive shell with the privileges of root or any "otheruser". No passwords required (if so configured). "exit" is required to terminate the shell, however.
0
 
LVL 13

Expert Comment

by:Sandy
ID: 40314532
you can use different multiple tty console basically  which i can consider as the simplest way. Else this is the method you are already doing is the suggested one..

One more suggestion if you can use "screen" command to get rid of it.

TY/SA
0
 
LVL 1

Author Comment

by:rwniceing
ID: 40314592
Sandy, what you mean use  "different multiple tty console"
Now I am using putty to remotely access my root access and user accounts on my window 7 computer

What is screen command for ?

If you provide more procedures that will be better understanding
0
 
LVL 13

Accepted Solution

by:
Sandy earned 250 total points
ID: 40314612
if you are on remote.. "different multiple tty console" doesn't make sense....

So.. screen command is to initialize and join the screen later .. .eg.

user1$ screen -S scr1
user1$exit

root#screen -x scr1
root# exit

so whenever you want you can initialize multiple screen with multiple users and then you can use them.

TY/SA
0
 
LVL 1

Author Closing Comment

by:rwniceing
ID: 40321673
Thanks for your reply
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
1. Introduction As many people are interested in Linux but not as many are interested or knowledgeable (enough) to install Linux on their system, here is a safe way to try out Linux on your existing (Windows) system. The idea is that you insta…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now