Solved

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

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
You ever wonder how to backup Linux system files just like Windows System Restore?  Well you can use Timeshift in Linux to perform those similar action.  This tutorial will show you how to backup your system files and keep regular intervals. Note…
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…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

863 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

24 Experts available now in Live!

Get 1:1 Help Now