In this project, you will implement a bash script which applies default Bash profile configurations for new added Linux users.
This project is aimed for beginners who want to get familiar with Git and GitHub workflows, debug Linux errors and turn Linux commands towards a mature Bash script.
- Fork this repo by clicking Fork in the top-right corner of the page.
- Clone your forked repository by:
Change
git clone https://github.com/<your-username>/<your-project-repo-name>
<your-username>
and<your-project-repo-name>
according to your GitHub username and the name you gave to your fork. E.g.git clone https://github.com/johndoe/BashProject
. - Open the repo as a code project in your favorite IDE (Pycharm, VSCode, etc..).
Later on, you are encouraged to change the README.md
file content to provide relevant information about your project.
Let's get started...
In many Linux systems, the /etc/skel
directory provides a way to assure new users are added to your Linux system with default Bash profile configurations.
When adding a new user with the adduser
command, it will create the user's home directory (usually under /home/<username>
), and copy files from /etc/skel
to the new user's home directory.
Typically, the /etc/skel
directory contains a file called .bash_profile
. This file, when copied to the user's home directory, can customize the Bash environment of the user.
The /etc/skel
directory itself is owned by the root
user and has restrictive permissions (mode 755
), which means that only the root
user can modify its contents.
- In
/etc/skel
edit the.bash_profile
file (or create it if it doesn’t exist) using your favorite text editor (nano
,vi
, etc...) as detailed below. It's highly recommended to backup the original file before you start.-
Greet the user. E.g. if the username is john, the message
Hello john
will be printed to stdout. -
Define an environment variable called
COURSE_ID
with a value equals toDevOpsFursa
. -
If the file
.token
exists in the home directory of the user, check its permissions. If the octal representation of the permissions set is different from600
(read and write by the user only), print the following warning message to the user:Warning: .token file has too open permissions
-
Change the
umask
of the user such that the default permissions of new created files will ber
andw
for the user and the group only. -
Add
/home/<username>/usercommands
(while<username>
is the linux username) to the end of thePATH
env var. -
Print the current
date
on screen in ISO 8601 format. The precision should be seconds, and the timezone should be UTC. The correct format should look like:2022-03-18T08:54:21+00:00
. -
Define a command alias, as follows - whenever the user is executing
ltxt
, all files with.txt
extension are printed (tip: wildcards). -
If it doesn't exist, create the
~/tmp
directory on the user's home dir. If it exists, clean it (delete all the directory's content without removing the dir itself). -
If it exists, kill the process that is bound to port
8080
(ports will be discussed later on in the course). This resource may help. -
Feel free to add any additional configurations of yours.
-
- Create a new Linux user using
adduser
command. If everything is done well, the new user's Bash environment should have the custom script profile you created. - Login to the new user terminal session:
su -l <username>
. Replace<username>
to the created user. Example for the user's terminal behavior might be:
username@localhost:~$ su -l john
Password:
Hello john
Warning: .token file has too open permissions
The current date is: 2022-03-18T08:54:21+00:00
john@localhost:~$ ltxt
a.txt
john@localhost:~$ echo $COURSE_ID
DevOpsFursa
john@localhost:~$ ls -l tmp
total 0
john@localhost:~$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/john/usercommands
- When done, copy the content of your
/etc/skel/.bash_profile
file intobash_project/.bash_profile
in this repo.
Time to submit your solution for testing.
- Commit your changes. The only file that has to be committed is
.bash_profile
. - Push your commits to GitHub.
- In GitHub Actions, watch the automated test execution workflow (enable Actions if needed). If there are any failures, click on the failed job and read the test logs carefully. Fix your solution, commit and push again.
Upon successful test execution, you'll see a green checkmark (✅) and the following message would be printed in the test logs:
Well Done! you've passed all tests