Solved

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

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Centos 7 User to Start Apache, MariaDB, LDAP 5 41
nagios 4 php error after installation 6 95
linux redhat 7.2 10 74
Upgrade BIOS / EUFI at Scale 4 36
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…
Fine Tune your automatic Updates for Ubuntu / Debian
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.:
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

809 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