Solved

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

Posted on 2014-09-10
5
463 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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.:
Suggested Courses

631 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