Is there a way to edit bashrc without loging into a user account

0

I have a probpem with Manjaro Linux. I worked with Android Studio and I added some lines to bashrc file.

Now. Every time I try to login into that user it is stuck after I enter valid password. When I enter wrong one it says 'Wrong password' and tells me to log in again.

I am 90% sure that problem is in bashrc file but the thing is that I can't open it to edit it.

I logged into tty as a root but the bashrc file there is not same one as in my user's account.

So. Is there any way to edit my bashrc from tty or something simillar. I want to avoid reinstalling the system.

Thank you.

Mileta Dulovic

Posted 2019-09-20T10:28:50.400

Reputation: 113

You should be able to edit it either from safe mode command prompt or an external live boot disc. – AFH – 2019-09-20T10:39:39.287

Safe mode command prompt? Are you thinking about tty? If so.. I can't.. None of the linux commands work in it unless I login as root but then it's the same bashrc that I don't want to edit. – Mileta Dulovic – 2019-09-20T10:43:13.853

Safe Mode or Recovery Mode is a separate advanced boot option in Ubuntu, so I assume there is something analogous in Manjaro. If not, that's why I suggested the alternative of using a live boot. – AFH – 2019-09-20T10:59:27.467

Answers

0

First off, I'm not completely sure what bashrc you're referring to. There's a .bashrc in a user's home: ~/.bashrc, there's also one in /etc/bash.bashrc.

I suppose you're referring to ~/.bashrc of your user. Then you already managed to do the first part, that is to log in as root. Then you just need to navigate to the user home and edit the file there.

I think you see a different ~/.bashrc because when you log in as root, you are in the root home, so when just typing sth like $ vi .bashrc you open the root's .bashrc file.

pavelsaman

Posted 2019-09-20T10:28:50.400

Reputation: 158

Thank you so much :). It did the job. I was blind :D – Mileta Dulovic – 2019-09-20T10:48:54.653

Not at all, good it's working now :) – pavelsaman – 2019-09-20T10:49:25.210

0

When I enter wrong one it says 'Wrong password' and tells me to log in again.

It may not be because of .bashrc. You (as root) can change the user's password:

# as root
passwd username

After this try to log in with username and the new password.


This fragment is in case it's really about the user's .bashrc.

~username/.bashrc should expand to the path of .bashrc in the home directory of the existing user username. This way you can locate the file (e.g. printf '%s\n' ~username/.bashrc).

Editing it as root may not be a good idea because it may not alter the file in place; it may create a new copy and then overwrite the old file. This may result in wrong ownership and permissions.

This should work:

# as root
sudo -u username nano ~username/.bashrc

(nano is just one possibility, use any editor you like).

Note: if there is encryption involved then it may be the user's home directory is decrypted and mounted only after the user logs in. In this case you need additional (encryption-related) steps to get to the right .bashrc file.

Kamil Maciorowski

Posted 2019-09-20T10:28:50.400

Reputation: 38 429

Thank you for your time. Problem was in bashrc as I suspected. :) – Mileta Dulovic – 2019-09-20T10:50:18.150