I downloaded Kali linux, great os if you ask me, but I want to set the PATH to /sbin/
How do I do that, I want to set it permanantly and how do I make my account root so that I can create new files in /etc ... and so forth?

Dani AI

Generated

Short, practical answers that avoid the common pitfalls mentioned by and .

To make /sbin available permanently for your user without repeatedly concatenating entries, add a guarded export to a login/profile file (choose ~/.bash_profile if you use a Bash login shell, otherwise ~/.profile). The guard prevents duplicate entries:

# put this in ~/.profile or ~/.bash_profile
case ":$PATH:" in
  *":/sbin:"*) ;;
  *) PATH="/sbin:$PATH"
esac
export PATH

For a system-wide change (all users), drop a small script into /etc/profile.d/ so it runs for login shells:

# example /etc/profile.d/localpath.sh (create as root)
if ! echo ":$PATH:" | grep -q ':/sbin:'; then
  PATH="/sbin:$PATH"
fi
export PATH

Do not replace PATH with just /sbin — that will remove /usr/bin and other directories and break ordinary commands. After editing a profile file, either log out/in or source the file to apply changes for the current session.

Regarding root access: the safer approach is to grant your user sudo privileges rather than enabling a root login. On Debian-derived systems add the account to the sudo group (or wheel on some distros) and edit privileges with visudo when needed. If you must edit files under /etc, prefer sudoedit or using an editor via sudo so file permissions are preserved.

Troubleshooting notes: if a PATH change appears duplicated, check all files read by your shell (/etc/profile, /etc/profile.d/*, ~/.profile, ~/.bash_profile, ~/.bashrc) — adjust only one of them so you don’t append repeatedly.

Recommended Answers

All 5 Replies

Normally, you should have sudo privileges. In that case, you can run any commands you want under root-privileges by writing sudo before it, like:

$ cd /sbin/
/sbin$ sudo mkdir test_dir
[sudo] password for YOUR_USERNAME: 
/sbin$ cd test_dir
/sbin/test_dir$ 

To actually switch the root user within a command terminal (for all subsequent commands), you can do sudo su (i.e., su means "super-user", another name for "root" user). Simply as so:

/sbin$ sudo su
[sudo] password for YOUR_USERNAME: 
/sbin#

(notice that the dollar sign becomes a # sign when you are logged as root. And you type the command exit to go back to normal user account. Of course, this only applies to that terminal session.

As root user (through sudo su) you can also change the root password with the command passwd. Afterwards, you can login as username "root" and with that password. However, it is not recommended to ever do that. You should just use sudo whenever you need to do things that require root privileges, and use sudo su occasionally when you want to do many root-privilege commands.

As for setting things like the PATH variable, these things are usually set in the .bashrc file in your user's home folder. This is a kind of "loading personal settings" file. There are also other files for that, I'm not sure anymore which.

Actually Mike, you don't want to set PATH in .bashrc, as it is executed on each invocation of bash, sometimes resulting in PATH variables like "/sbin:/sbin:/sbin:/usr/bin:...". Path should only be set (in my opinion) in .bash_profile, or in a manually run script when you need to temporarily add a new link to PATH.

Thanks for the clarification, the whole bashrc / bash_profile / profile business is confusing sometimes.

NP Mike. I've run into the "massively concatenated environment variable" issue before, even to the point of exceeding the maximum length of an environment variable. That's how I know about the problem! :-) You know that old saw - "It hurts when I do that!" - resp. "Then don't do that!"...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.