Solved

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

Posted on 2014-09-10
5
459 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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Coding C# in Linux 8 134
VMware Workstation 12 Player 16 133
SonarQube on Linux vs Windows 3 53
VMware Tools Install On Linux Problem 3 85
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…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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.:

820 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