Monday, November 9, 2020

How to Enable Adduser on Debian

 I prefer to use adduser over useradd when possible. It simply is more logical to my mind. One time when I installed Debian, though I knew it was a Debian based program, when I typed in:

sudo adduser

All I saw in return is the "Program not found" or something similar. I discovered after checking on it using:

which adduser

. . . that it resided in the /usr/sbin directory. After doing a check on the $PATH environment variable using:

sudo env

My suspicions were confirmed--that /usr/sbin was not in the $PATH variable. Why doesn't Debian put it there by default? Hard to say. It appears that they do have the /sbin directory in the path, which should point to /usr/sbin since it is a symbolic link At any rate, not knowing at the time how Linux processed the $PATH and where I should put it, I proceeded to do some research. In DOS, everything used to go into the Autoexec.bat file, which always was run on startup. 

To make a long story shorter, what I discovered was that one: There was one difference between how the DOS and Linux path statements were used. For Linux, the big difference is you put "export" before the PATH= part. So the statement to add to the appropriate file is:

export PATH=$PATH:/usr/sbin

All caps on the PATH part is important, and the colon separates each entry. Putting $PATH on the right side of the =, appends what you add to it. So if the PATH statement echos out "/usr/bin" the resulting output from the above export statement would be "/usr/bin:/usr/sbin". The "export" command makes it usable beyond this one instance which is what you want.

Two: Where to put it? That turned out to be more complicated that one might think. There were multiple files to try. There is a file to put it in if you want only one user to use it, another for all users on the system except for root, and yet another if you only want root to have access to it. On top of that, the file you put it in can differ between major distributions. Like the Mandrake version I saw given as an example that one website used ".bash_profile" whereas in Debian, it is ".bashrc".

Since I figured where as the user programs are mostly installed in the /usr/bin directory, which was included in the PATH by default, that the /usr/sbin directory contained programs that would be more system type files that should primarily be accessed by a root user. So obviously, it would go in the root's home directory, which is at /root as it turns out. So, you would want to enter the following to edit that file in the root home directory:

sudo nano /root/.bashrc

Then add the line at the end of the file:

export PATH=$PATH:/usr/sbin

When I did that, it worked when I attempted to access the program from root using sudo, but not as just a simple user.

(Note: the period it begins with means it is a hidden system file. Use Ctrl-H in your file manager to see it or "ls -a" if using the command line.)

You can use

sudo env

To verify that /usr/sbin is now part of the $PATH variable. Now you should be able to run

adduser --help

As well as any other programs in the /usr/sbin directory!

May the Linux force be with you!


No comments:

Post a Comment