3

This might be a weird question but I wonder if there are possibilities to this.

When I'm configuring a system I prefer to be root so that I don't have to sudo everything. However, the root account is not my personal account so other people might get anoyed if I change settings in the root account (like the bashrc and vimrc). Therefor, I would want to go back using my personal account to do the configuration, but then I don't have permissions.

I don't have problem this with the root account only, sometimes I need to do stuff on another user account too.

What would be ideal is that I can authenticate myself as a different user (or the root account) but not be logged in as it.

I know I can also log in as a certain user and then manually execute my personal profile's config files (like the bashrc and vimrc), but that seems like an annoying task to do every time.

Does anyone know ways to efficiently do what I am describing here? Or do you guys think it is weird and shouldn't be done?

2
  • not sure what you want buut a combination of "su" and "source" commands might do the trick.
    – vfbsilva
    Aug 16, 2013 at 11:27
  • @vfbsilva see my 5th paragraph
    – gitaarik
    Aug 16, 2013 at 11:46

2 Answers 2

2

I don't think there is the generic all solving answer to this problem. You cannot be two users at once. Whenever you run a command the shell would have to guess as which user that command should be executed. When you create a file it would have to guess who it should belong to and so on and so forth.

I do your 5th paragraph. I have a script in /usr/local/bin (i called it becomeme) which sources my /home/user/.bashrc and adapts PATH, LD_LIBRARY_PATH, MANPATH and PKG_CONFIG_PATH, to include paths to my home directory. I also put some wrappers, for example to replace vi with HOME=/home/me vi. I basically wrap stuff to search my user's home directory for config. For the simple use cases bashrc, vi and screen it works fairly well.

This however only works to a certain extent, because accessing my home directory as another user generally means that user needs to have write permissions for some files and directotires, which I don't want. So it's more a hack for most common usecases, vi and screen mostly.

It's not very complicated, as I just need to remember to type becomeme after switching to another user. For root this worked fairly quickly, for other users I had to give permission to the files in my home first.

Another approach, which I haven't tried yet, but may work for your use case: Create another user with UID 0 and your user's home. You simply need to add a line to /etc/passwd and /etc/shadow. For example if your root-username was admin, the corresponding line in /etc/passwd might look like this:

admin:x:0:0:My personalized root account:/home/mynormaluser:/bin/bash

Then you type passwd admin to create an entry in /etc/shadow. If you log in as admin now, it will be UID 0, i.e. root, but have your normal home directory and therefore its settings from your normal user. It also has its own password, you don't need to share. This doesn't work for NFS-home though (see root_squash).

While this can work, it may create some minor issues with file permissions, whenever you create files as user admin in your home directory. You could work around those issues with proper creation masks and a designated group you share only between your user and admin.

1

Dual authentication

To my knowledge there is no way to accomplish what you're asking for.

Alternatives

multiple terminals

You can always have multiple windows open. I often have multiple tabs going in gnome-terminal and some are logged into other accounts on other systems while others still are just on my local system.

screen & tmux

Another altnerative would be to learn how to use screen or tmux so that you can switch back and forth between windows. I often use this in addition to the multiple tabs in gnome-terminal.

This approach has the added benefit of being able to disconnect from a remote system and reconnect later on, so that my terminal session is saved.

alternative sudo workflows

You can gain some access to your environment's aliases through the use of this trick. Setup an alias like so:

$ alias sudo='sudo '

NOTE: the space after the command. From then on, sudo will work normally and you'll be able to use your user's aliases without issue (both normally and with root privileges).

More details on how this works can be found here.

excerpt

If the last character of the alias value is a space or tab character, then the next command word following the alias is also checked for alias expansion.

You could also load your environment's .profile like so with this alias:

$ alias sudo='sudo su -i ENV=/home/myuser/.profile'

What else?

The workflow that you're getting tripped up with is just how the environment works in Unix. So it's best to try and adapt to it, and make repetitive tasks either scripted or aliases so that they are not.

If you find that particular things are needed by you when logging into system accounts such as root you might want to try and work with others that have the same elevated rights to agree upon some standards within these accounts.

If you're creating shortcuts and aliases chances are other either ARE or SHOULD be so that they're as productive as you.

3
  • Disclaimer: While I have been bashing against sudo lately, this is not meant offensive at all. Actual comment: How does this solve the issue at hand? It would seem this rather leeds to an increased use of sudo, yet the OP is already at a point where (s)he states 'I prefer to be root so that I don't have to sudo everything'.
    – Bananguin
    Aug 16, 2013 at 15:08
  • @user1129682 - there isn't any way to get around using sudo but still have access to your environment. I'm offering him ways to make it less restrictive.
    – slm
    Aug 16, 2013 at 15:19
  • After your edit I see where you were going with your answer.
    – Bananguin
    Aug 16, 2013 at 17:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.