Linux Foundation LFCS Question Answer
Task
In the Git repository cloned to ~/optimal-bedbug, edit the file hosts. Uncomment all the host entries in the group [webservers].
Finally, commit the change in file hosts using the commit message Enables missing hosts and push the commit to the remote.
The Answer Is:
See the complete solution in Explanation.
This question includes an explanation.
Explanation:
Step 1: Connect to the correct Linux server.
The video specifies that this task must be completed on host lfcs00100.
From the candidate terminal, execute:
ssh lfcs00100
This establishes an SSH connection to the designated server.
All remaining commands must be executed on this host.
Step 2: Navigate to the existing Git repository.
Execute:
cd ~/optimal-bedbug
- cd changes the current directory.
- ~ refers to the current user's home directory.
- optimal-bedbug is the existing Git repository specified in the task.
Verify the current working directory:
pwd
List the repository contents:
ls -la
Check whether it is a valid Git repository:
git rev-parse --show-toplevel
The output should identify the root directory of optimal-bedbug.
The repository is already cloned. Therefore, there is no requirement to execute git init or git clone.
Step 3: Inspect the repository status.
Execute:
git status
This displays the current branch, modified files, staged changes, and working tree status.
Also execute:
git branch --show-current
This identifies the active branch.
Check the configured remote:
git remote -v
An example output might be:
origin git@example.com:training/optimal-bedbug.git (fetch)
origin git@example.com:training/optimal-bedbug.git (push)
The remote URL is illustrative. Use the remote already configured in the existing repository.
Do not modify unrelated repository configuration.
Step 4: Locate and inspect the hosts file.
Execute:
ls -l hosts
Display its complete contents:
cat hosts
The task requires editing the file named hosts in the repository.
Locate the section:
[webservers]
This is an inventory-style group heading.
The entries belonging to [webservers] appear below the heading and continue until the next group heading or the end of the file.
Step 5: Identify the commented host entries.
To display the [webservers] section, execute:
awk '
/^\[webservers\]$/ {inside=1; print; next}
/^\[/ {inside=0}
inside {print}
' hosts
- awk processes the file line by line.
- /^\[webservers\]$/ identifies the exact group heading.
- inside=1 enables output for the selected group.
- /^\[/ identifies a subsequent group heading.
- inside=0 stops output when another group begins.
- inside {print} displays entries belonging to [webservers].
Look for host entries beginning with #.
For illustration, the original section might look like:
[webservers]
#192.168.10.11
#192.168.10.12
192.168.10.13
#192.168.10.14
[dbservers]
#192.168.20.11
192.168.20.12
These addresses are examples only. Preserve the actual addresses and hostnames found in the video environment.
The task requires uncommenting all host entries in [webservers] only.
Step 6: Edit the hosts file.
Open the file using Nano:
nano hosts
Alternatively, use Vim:
vim hosts
Navigate to:
[webservers]
Remove the leading comment character # from every commented host entry in that group.
For example:
Before:
[webservers]
#192.168.10.11
#192.168.10.12
192.168.10.13
#192.168.10.14
[dbservers]
#192.168.20.11
192.168.20.12
After:
[webservers]
192.168.10.11
192.168.10.12
192.168.10.13
192.168.10.14
[dbservers]
#192.168.20.11
192.168.20.12
Important requirements:
- Remove # only from commented host entries belonging to [webservers].
- Do not remove the [webservers] group heading.
- Do not change the IP addresses or hostnames.
- Do not uncomment entries belonging to other groups.
- Do not remove comments that are descriptive notes rather than host entries.
- Preserve the original file structure and unrelated content.
Step 7: Save the modified file.
If using Nano:
1. Press Ctrl + O.
2. Press Enter to save.
3. Press Ctrl + X to exit.
If using Vim:
1. Press Esc.
2. Type :wq.
3. Press Enter.
Step 8: Verify the changes before committing.
Execute:
git diff -- hosts
This displays the difference between the working version of hosts and its previous Git version.
For example:
[webservers]
-#192.168.10.11
-#192.168.10.12
+192.168.10.11
+192.168.10.12
192.168.10.13
-#192.168.10.14
+192.168.10.14
- Lines beginning with - were removed from the previous file version.
- Lines beginning with + were added.
- Unprefixed context lines are unchanged.
Confirm that the differences are limited to the requested modifications.
If unrelated lines have changed accidentally, correct them before proceeding.
Step 9: Stage the modified hosts file.
Execute:
git add hosts
git add places the current file contents into Git's staging area, also called the index.
This prepares the modification for the next commit.
Do not use:
git add .
because it stages all changed files under the current directory, potentially including unrelated modifications.
The task specifically concerns the hosts file.
Step 10: Verify the staged changes.
Execute:
git diff --cached -- hosts
This shows the changes staged for the commit.
Also check:
git diff --cached --name-only
Ideally, the only staged file should be:
hosts
If unrelated changes were previously staged, avoid including them in this task's commit.
Step 11: Commit the changes using the exact required message.
Execute:
git commit -m "Enables missing hosts"
- git commit creates a new commit from the staging area.
- -m provides the commit message directly.
- "Enables missing hosts" is the exact message specified in the task.
Do not change the spelling or capitalization.
A successful commit may produce output similar to:
[main a1b2c3d] Enables missing hosts
1 file changed, 3 insertions(+), 3 deletions(-)
The branch name, commit hash and change count will depend on the actual repository.
If unrelated changes are already staged, use the file-specific commit operation instead:
git commit --only -m "Enables missing hosts" -- hosts
This creates a commit containing the selected file's modification rather than unrelated staged files.
Step 12: Verify that the commit was created.
Execute:
git log -1 --oneline
The most recent commit should have the required message.
For example:
a1b2c3d Enables missing hosts
Check which files were included in the commit:
git show --stat --oneline HEAD
The commit should contain the requested modification to hosts.
You can inspect the full commit:
git show --format=fuller HEAD -- hosts
This confirms the exact lines committed.
Step 13: Push the commit to the remote repository.
Execute:
git push
The git push command transfers local commits to the configured remote repository and updates the destination branch.
If the current branch already tracks a remote branch, this should be sufficient.
A successful push may display output similar to:
To git@example.com:training/optimal-bedbug.git
123abcd..a1b2c3d main - > main
If Git reports that no upstream branch is configured, first inspect:
git remote -v
git branch --show-current
If the intended remote is origin, execute:
git push -u origin HEAD
- -u configures upstream tracking for the successfully pushed branch.
- origin specifies the destination remote.
- HEAD refers to the current local branch.
Do not use git push --force. Force-pushing can overwrite remote history and is not required by this task.
Git's official documentation confirms that git push updates remote references and that --set-upstream configures branch tracking.
git-push Documentation
Step 14: Verify that the push completed successfully.
Execute:
git status -sb
Inspect the branch's tracking relationship and whether any commits remain ahead of the remote-tracking branch.
Next:
git branch -vv
This displays the local branches and their upstream tracking information.
To check whether your latest commit has reached the configured upstream, execute:
git rev-parse HEAD
git rev-parse '@{upstream}'
For a straightforward successful push of the current branch, both hashes should normally be identical.
You can also check whether any local commits remain unpushed:
git log '@{upstream}..HEAD' --oneline
If it produces no output, the local branch contains no commits ahead of its upstream tracking reference.
A clean working tree alone does not prove a successful push. The remote update must succeed separately.
Step 15: Perform the final verification.
Execute:
cd ~/optimal-bedbug
git status
git log -1 --oneline
git show --format= --name-only HEAD
git branch -vv
Then inspect the [webservers] section again:
awk '
/^\[webservers\]$/ {inside=1; print; next}
/^\[/ {inside=0}
inside {print}
' hosts
Confirm that all required host entries are uncommented.
Final Solution
Essential commands in execution order
Copy commands
ssh lfcs00100
cd ~/optimal-bedbug
# Examine the repository and inventory
git status
cat hosts
# Edit the file
nano hosts
# Uncomment all host entries under [webservers]
# Save and close the editor
# Review the changes
git diff -- hosts
# Stage the modified file
git add hosts
# Verify staged changes
git diff --cached -- hosts
# Commit using the exact message
git commit -m "Enables missing hosts"
# Push to the configured remote
git push
# Final verification
git log -1 --oneline
git status -sb
Technical Verification and References
The solution has been checked against the official Git documentation.
- Git add: Adds modified file contents to the staging area in preparation for a commit.
GitHub
- Git commit: Records staged modifications as a new commit using the specified commit message.
git-commit Documentation
- Git push: Transfers commits to the configured remote repository and updates remote branch references.
git-push Documentation
Official documentation: Git Command Reference.
Expected result: All host entries within [webservers] in ~/optimal-bedbug/hosts are uncommented. The modification is committed with the exact message Enables missing hosts, and the new commit is successfully pushed to the remote repository.

