I'm using FreeBSD with bash as the shell. I also use SSH with both FreeNAS and pfSense, both FreeBSD based.

I'm getting confused about setting up bash options, and some clarification would really help. I'm trying to get various shell options to be used in future sessions (and exported to shells called from sessions) but I'm not having much luck. Perhaps I don't know how to find the correct file to put them in, or the correct way to put them there.

My main problem is probably just finding the rc file used for the session (!!) If I login as root, then execute su, then set will show me a different list of environment variables. But as I haven't changed user, I'm confused why my rc file doesn't seem to be the same. (the files I've found don't have different entries for the environment variables I'm looking at). The output of set shows ENV=/USERNAME/.shrc but when I edit this file and log back in, I don't see any changes to my session so I'm guessing this isn't where to look? But I've tied editing ~/.bashrc as well, and that doesn't seem to do anything either.

There should be a way to find out directly which .rc file was used to initiate the session, but I don't know how to do this, especially as both FreeNAS and pfSense might have their own customised locations.

Whether it's using one or two rc files, how can I find which rc file I would have to edit, to modify future sessions that are the same as the present session? And does it use one rc file or two different files if you first login as root and then su?

  • Why are you logging in as root?
    – Kusalananda
    Oct 9, 2017 at 16:46
  • Because it's an offline isolated test system, it's console rather than SSH over the wires, and because it allows me to isolate issues related to user rights/permissions (as I'm not very experienced yet). Once it's working nicely, I'll set up the server I'm actually going to use and su once logged in. Good question thanks though.
    – Stilez
    Oct 9, 2017 at 16:58

1 Answer 1


The FreeBSD default root shell is /bin/tcsh. You should not change the shell for the root user. You can comfortably use the bash shell. But then change the shell for your own user. If you need root privileges you should get the habit of using su -c or even better: sudo. If you do that you really do not care what the shell for the root user is. If you insist on changing the shell for root - then use the "toor" (root backwards) user. It still operates as uid 0 but it is safe to change the shell.

You reference ~/.bashrc but this is relative. On a typical FreeBSD install this will be expanded to /home/<username>/.bashrc for regular users and /root/.bashrc for the root user.

You write that you login as root. I recommend that you do not do that but rather log in as a regular user.

When an interactive shell that is not a login shell is started, bash reads and executes commands from ~/.bashrc, if that file exists. This means that .bashrc is not invoked on login! Only if you start it as an interactive shell.

You are probably looking for ~/.bash_profile - see https://forums.freebsd.org/threads/2682/

  • This gave me a good hint. Based on this answer, I looked up the bash startup and the files it's hard-coded to check, and found one of those was in use (~/.profile), so it wasn't checking the files I expected. As to the account, it's an offline test system. Root via console is safe to use. Obviously on a live system one would su. But well spotted and thank you anyhow for the tip.
    – Stilez
    Oct 9, 2017 at 17:04
  • FreeBSD comes with very good documentation. Learn to use "man". It is a short read for bash and gives your answers: freebsd.org/cgi/man.cgi?query=bash As a beginner make sure you get good habits. Even though you have console access I would recommend not to use root as login. Oct 10, 2017 at 8:37
  • Good. My point was that .profile was mentioned on the bash man page. All the TERM stuff is related to another questions :-) (Which is hard to grok from the man pages!) Oct 10, 2017 at 8:47
  • I've been using it solidly in every case, for the entire time I've been trying to learn the OS, as well as Google/SE. I asked because changing the files referred to by pages in man did nothing. It's such a huge subject that it's not always easy even to know what to look for. Man assumes some clue what to look for, and a well defined topic suited to its pages - knowing where might be promising to look. With the best will in the world, that's not always a beginners situation.
    – Stilez
    Oct 10, 2017 at 8:48
  • (Above 2 comments are reversed, I deleted and reposted mine due to 5 min timeout about the same time its reply was posted.)
    – Stilez
    Oct 10, 2017 at 8:56

You must log in to answer this question.

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