Change prompt in Ubuntu terminal - Hide hostname and working directory.

Oftentimes, I use Tmux to split my terminal windows to save time from switching between them. Although that was quite nice and useful, I always had one problem when working inside some directories located deep down my directory hierarchy. That is, whenever I split up my terminal, I'm always left with a small window for each terminal. So when I'm inside the deeper directories, the prompt takes much longer space to show the path and my prompt was always kept at the end of the window. That was really inconvenient.

Here's how it looked like:

Change prompt in Ubuntu terminal - Hide hostname and working directory.

I came up with this solution to get rid of that problem. I decided to change my prompt so it would only show my username and current directory instead of the full path. That would make my prompt very shorter and hence I would have enough space to type in my commands and see it all clearly. I was a little bit concerned about this as I still wanted to see my host name whenever I'm connected to a remote server through ssh because I often connect to multiple servers at once so it's important to see which server I'm in before running any commands. Anyway I realized I could make this change available only for my local user account so the usual prompt will be available to me whenever I'm connected to a ssh session.

Here's how to do that.

First edit your .bashrc file in your home directory.

vim ~/.bashrc
Locate the following code block.

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

You need to change the PS1 line to change the prompt. By default it is in username@host:workingDirectoryPath format. Here's how I have changed them.

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

If you notice well, you will see that I have removed the h and replaced w with W (which means hostname is removed and the full directory path is replaced by the current directory).

Save the file and quit vim.

Now we need to reload the bash configuration for our current terminal session. Just run the following command to load your new configs.

source ~/.bashrc
Once you run the above command, you should immidiately notice that your prompt is changed :) But now you won't see the full directory path in your prompt. You can still see it by running the following command.

Here's how it looks now.

Change prompt in Ubuntu terminal - Hide hostname and working directory.

That's it !! I hope this will be useful to someone. Please feel free to comment and let me know if I have missed anything or if you know a better way to do this.

Maria DB Fix - ERROR 1698 (28000): Access denied for user 'root'@'localhost' on a new installation.

Maria DB Fix - ERROR 1698 (28000): Access denied for user 'root'@'localhost' on a new installation.

Today I installed MariaDB on my laptop and faced this weird issue. After the installation, I tried to login to the DB shell using the user 'root' and the blank password. Then it returned me this error message stating:

ERROR 1698 (28000): Access denied for user 'root'@'localhost'
My first guess was that they might have changed the default password and set it to something else. So I did some research and realized it was not the case here. The actual problem was related to the authentication process of MariaDB.

MariaDB uses a plugin called UNIX_SOCKET to authenticate users, which allows them to use the operting system credentials to login. If I wanted to login to MariaDB using the root user, it first requires me to logged into my system as root (which I can temporarily take access using the sudo command.)

But since I'm logged in as the user nimeshka, I cannot request MariaDB to login as another user (in this case, root). So if I enter the command,

mysql -uroot -p
it would tell me that I have no permissions to login. Why? because I'm authenticated to the Ubuntu system as nimeshka, so MariaDB won't trust me when I ask it to login as root :P So it is clear that if I enter the following command, it would allow me to log in.

sudo mysql
You should also note that If I had created a user in mysql with the username nimeshka, I could have logged in to the shell by just entering the mysql command (it will take my current system username and will log me in as the particular mysql user)

Another thing to note: As I was concerned why I didn't face this issue when I installed MariaDB earlier, I looked for a bit more details in their documentation and found a satisfying answer. It says that they use the UNIX_SOCKET plugin by default in new installations of Ubuntu 15 and later (I used to install MariaDB in Ubuntu 14 earlier and today I tried it in Ubuntu 16, which makes sense!).

So here is how to disable the UNIX_SOCKET plugin for root user.

# First we will login with sudo (means root)
$ sudo mysql -u root

# Then switch to the mysql DB.
MariaDB [(none)]> use mysql

# Then we will update the authentication plugin for root user by running the following query.

MariaDB [(none)]> update user set plugin='' where User='root';

# We need to flush privilages and exit the session.
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> quit

That's it guys, hope this will be useful for someone :)