2

logged in as root, environmental variables are great. I typed "set"

I did:

useradd -m alex
su alex

For some reason, everything is gone when I type "set". How do I make it so that alex has all the environmental variables just like root (except as a standard user), when I first logged in?

For example, I want PS1 to be set, just like the root account. All my environmental variables were erased when I created this new user.

**Edit: people are not understanding the question. Right now, "alex" user account is completely blank, with no environmental variables. I just want it to have SIMILAR environmental variables like ROOT. All the directories have no color. The PS1 is just a dollar sign. That's not normal.

1
  • 2
    root is root. why do you want to set alex as root??
    – user31894
    Nov 11, 2009 at 11:32

6 Answers 6

1

All your users (assuming you're using bash) will execute /etc/profile on login. You may also need to set up your ~/.profile file. To do that you could copy root's profile or capture the output of (run as root):

set

and then edit that file to incorporate it into alex's .profile.

4

You want to use su - alex, not su alex.

From man su:

Options:  
     -, -l, --login  
         make the shell a login shell 

The login shell means your shell will process the initial-login scripts properly.

You could do the same thing by logging out and logging back in as your new user.

1
  • yeah - su with out the - doesn't do what you might otherwise think it would
    – warren
    Nov 11, 2009 at 13:25
1

First, check and see what's in /etc/profile.

Next, what shell does your alex user have set in /etc/passwd? Try looking at the appropriate rc file for whichever shell is set - for instance, if using bash, look for the default bashrc file (oftentimes at /etc/bashrc or a similar path). Likewise for other shells and their default startup scripts.

2
  • +1 just want to add help.ubuntu.com/community/EnvironmentVariables - see about halfway down "Persistent environment variables"
    – pjc50
    Nov 11, 2009 at 11:46
  • good troubleshooting tips but i think this user's trouble is described in teddy's answer. if the trouble persists after a real login, then start with these tips. Nov 11, 2009 at 12:17
0

You don't. Just don't use root for your everyday use. Actually, never login as root. Just use 'sudo' when you need to perform an administrative task.

You may think it's inconvenient and etc, but one day, after you screw up bad, you'll understand. It happens to everyone at some point.

If you need specific environment variables for your user, just set them in your .bash_profile or .bashrc files.

1
  • 1
    not the problem described. (good advice tho.) Nov 11, 2009 at 12:14
0

You can pass a lot more arguments to useradd.

useradd -ms /bin/bash username

This will create a user, its home direrctory and set it's shell to bash (using the default settings stored in /etc/bash.bashrc).

1
  • Or you can set up defaults in /etc/default/useradd and /etc/skel, if enabled (or similar files). Nov 11, 2009 at 14:40
0

You wanted to use the adduser command.

justin@eee:~$ man useradd|grep DESC -A 1
DESCRIPTION
       useradd is a low level utility for adding users. On Debian, administrators 
       should usually use adduser(8) instead.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .