change user name in bash prompt

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
ckonn
Level 3
Level 3
Posts: 180
Joined: Wed Oct 01, 2014 7:03 pm

change user name in bash prompt

Post by ckonn »

Hello,

I would like to ask how could I change the user name in bash prompt?

For example: from 'tom@dell ~ $' to 'dan@dell ~ $'

Thank you in advance
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
all41
Level 19
Level 19
Posts: 9520
Joined: Tue Dec 31, 2013 9:12 am
Location: Computer, Car, Cage

Re: change user name in bash prompt

Post by all41 »

Look in Control Center (Settings) Users and Groups
You can change the name there
Everything in life was difficult before it became easy.
Cosmo.
Level 24
Level 24
Posts: 22968
Joined: Sat Dec 06, 2014 7:34 am

Re: change user name in bash prompt

Post by Cosmo. »

Sorry, ths will not work, as it only changes the display name but not the technical user name. There are many things related with this and things are likely to get broken by changing it.

Create a new user account with the changed name, than copy (don't move!) the user data from the old into the new account.

Attention: Don't miss to add the new account into the group sudo, before you you remove the old one, otherwise you will fall in troubles.
WharfRat

Re: change user name in bash prompt

Post by WharfRat »

Actually you can change it to whatever you want.

Use the following line in your ~/.bashrc

Code: Select all

! [[ ${EUID} == 0 ]] && PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\][dan@\h]\[\033[01;34m\] \w \$\[\033[00m\] ' || \
	PS1='${debian_chroot:+($debian_chroot)}\[\033[01;31m\]\u\[\033[01;34m\] \W \$\[\033[00m\] '
You can copy and paste it in the terminal to test it out :wink:
ckonn
Level 3
Level 3
Posts: 180
Joined: Wed Oct 01, 2014 7:03 pm

Re: change user name in bash prompt

Post by ckonn »

WharfRat wrote:Actually you can change it to whatever you want.

Use the following line in your ~/.bashrc

Code: Select all

! [[ ${EUID} == 0 ]] && PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\][dan@\h]\[\033[01;34m\] \w \$\[\033[00m\] ' || \
	PS1='${debian_chroot:+($debian_chroot)}\[\033[01;31m\]\u\[\033[01;34m\] \W \$\[\033[00m\] '
You can copy and paste it in the terminal to test it out :wink:
Unfortunately I do not have .bashrc file in my home directory.
User avatar
austin.texas
Level 20
Level 20
Posts: 12003
Joined: Tue Nov 17, 2009 3:57 pm
Location: at /home

Re: change user name in bash prompt

Post by austin.texas »

ckonn wrote:Unfortunately I do not have .bashrc file in my home directory.
That is no problem. Paste the command into a new text file and save the file as .bashrc
Log out and back in to see the effect.
Mint 18.2 Cinnamon, Quad core AMD A8-3870 with Radeon HD Graphics 6550D, 8GB DDR3, Ralink RT2561/RT61 802.11g PCI
Linux Linx 2018
ckonn
Level 3
Level 3
Posts: 180
Joined: Wed Oct 01, 2014 7:03 pm

Re: change user name in bash prompt

Post by ckonn »

austin.texas wrote:
ckonn wrote:Unfortunately I do not have .bashrc file in my home directory.
That is no problem. Paste the command into a new text file and save the file as .bashrc
Log out and back in to see the effect.
It works! It's beautiful! Really, really beautiful!

A Big Thanks to everyone!
lmuserx4849

Re: change user name in bash prompt

Post by lmuserx4849 »

To read more about the command prompt:

Bash Reference - Controlling the Prompt

Bash Prompt HOWTO

Bash - Colors and formatting

Read about PS1, prompting, and .bashrc in man bash.
If easier, man pages can be read in your browser in html format using the -H option, man -H bash.
Locked

Return to “Scripts & Bash”