1

I have an assignment and I'm confused which bash configuration file to edit.

I'm supposed to edit a bash configuration file and change the PS1 prompt and add an environment variable that searches ~/scripts whenever a root user enters a command. I am then supposed to copy it to the appropriate directory so all new created users will also have the variables.

I can do the first part fine, but am not sure which configuration file I am supposed to be editing. Based on the second requirement, I'm editing ~/.bashrc, but then I'm stuck on the second part of which directory to copy to.

NDG says that all files in that directory with a .sh extension are automatically executed in /etc/profile.d/, so I went ahead and copy/renamed ~/.bashrc to something like bashrc.sh there. But when I test it with a new user profile, there is an empty prompt in terminal.

Hopefully someone here can help me, thanks.


The exact wording of the assignment

  1. In the appropriate bash shell configuration file, configure the primary command line prompt so that it displays your surname, followed by @, the host name, and the working directory.
  2. Create a directory named ~/scripts
  3. In the appropriate bash shell configuration file, change the appropriate environment variable so that the system also searches the newly created ~/scripts directory when the root user enters a command.
  4. Copy the bash shell configuration file that you modified the steps above, to the appropriate directory so that whenever a new user is created, that user will also have these environment variable values.

marked as duplicate by jasonwryan, G-Man, DarkHeart, countermode, Anthony Geoghegan Apr 27 '17 at 9:00

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    @jasonwryan No, that thread doesn't have the answer to this question. – Gilles Apr 26 '17 at 23:11
1

You seem to be doing fine editing .bashrc; the directory that you also need to copy the templates of any configuration/script file to be duplicated upon the creation of a user is usually located at /etc/skel.

So you would do:

  1. Append to ~/.bashrc and place there:

    PS1="surname@\h\w>"
    
  2. Create the placeholder for future user scripts at ~/scripts

    mkdir ~/scripts
    
  3. Append to ~/.bashrc a $PATH modifier for it to search for scripts; as a rule of thumb for security reasons you append it at the end, and not at the beginning

    PATH=$PATH:~/scripts
    
  4. In this last part, you need to do it as root, or belonging to the sudo group, preceding the command with sudo to have super-user privileges; your normal user default privileges won't be enough to write in the /etc/skel directory. As in

    sudo cp ~/.bashrc /etc/skel
    

    or as the root user:

    cp  ~your_user_name/.bashrc /etc/skel
    

See the relevant link for more details about /etc/skel

The /etc/skel directory contains files and directories that are automatically copied over to a new user's home directory when such user is created by the useradd program.

/etc/skel allows a system administrator to create a default home directory for all new users on a computer or network and thus to make certain that all users begin with the same settings or environment.

Several user configuration files are placed in /etc/skel by default when the operating system is installed.

The name of the directory skel is derived from the word skeleton, because the files it contains form the basic structure for users' home directories.

As for the PATH environment variable, see this

The PATH environment variable is a colon-delimited list of directories that your shell searches through when you enter a command.

Program files (executables) are kept in many different places on the Unix system. Your path tells the Unix shell where to look on the system when you request a particular program.

For altering your prompt with PS1, you can play with the .bashrc PS1 generator and see the modifications on real time using a quite clever web page.

Not the answer you're looking for? Browse other questions tagged or ask your own question.