0

I am quite new to Linux and I was wondering how to change the following when in terminal permanently. When I set up my computer I used a name that I now want to change:

In terminal, the name I want to change would be of this form:

TheNameIWantToChange@HostName ~ $

So my question is, what exactly is this name and how do I go about changing it? Thanks!

3

If I understand correctly you'd like to change your user name.

usermod -l TheNameIWantToChange -d /home/TheNameIWantToChange -m CurrentName

usermod : modify an account
-l : change the name
-d : chnage the location (name) of the home directory
-m : move the contents of the current home dir to the new one

E.g. suppose current name is albert and you'd like to change it to benny:

sudo usermod -l benny -d /home/benny -m albert

As an added bonus, you can use environment variables:

NewUser="benny"
sudo usermod -l ${NewUser} -d /home/${NewUser} -m $USER
  • 1
    Note that important caveats are listed in the usermod(8) manual, such as crontab or at job files, etc. – thrig Oct 2 '15 at 23:46
  • I tried the first usermod command you listed however I got "sudo: unable to resolve host HostName" and "usermod: user TheNameIWantToChange is currently used by process 2559" – Paradox Oct 3 '15 at 0:21
  • EDIT: Now, I only get "usermod: user TheNameIWantToChange is currently used by process 2559 – Paradox Oct 3 '15 at 0:32
  • can you provide the output of ps -q 2559? In any event, it seems like the user TheNameIWantToChange already exists on your system. To make it clearer, can you list all the users you created (not system created users)? – Dani_l Oct 3 '15 at 0:53
1

Alternatively if you don't want to change your username and you're just interested in changing what you see at your prompt there you can alter the PS1 environmental variable.

PS1 is a variable that Bourne shell uses to set how your terminal is displayed. You can customize it in a few ways:

For testing I'd recommend just altering the variable from within your session, that way if you don't like the changes you can easily fix them.

export PS1="\h:\w\$"

Where \h is hostname, \w is the current working directory and \$ is just a dollar sign. So you will see HOSTNAME:/path/to/current/dir$ You could also set some custom message:

export PS1="MYMESSAGE@\h:\w\$"

If you like what you see then you can change it permanently by alter your .bashrc file. To do this use your editor of choice and open the file ~/.bashrc

look for the following:

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi

and get rid of the \u@:

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\h:\w\$ '
fi

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.