In this guide, we’ll walk through a practical DevOps task:
✅ Copying a file from a jump host to a storage server,
✅ Adding that file to a Git repository,
✅ Committing and pushing it to the master
branch,
✅ And fixing a common Git permission error (index.lock: Permission denied
) if it shows up.
🧩 Scenario
- A Git repository has been cloned to
/usr/src/kodekloudrepos/apps
on a storage server - A sample
index.html
file is available on a jump host at/tmp/index.html
- You’ve been asked to:
- Copy this file from the jump host to the storage server
- Add and commit it to Git
- Push the change to the
master
branch
🛰️ Step 1: Copy the File from Jump Host to Storage Server
From the jump host, use scp
:
scp /tmp/index.html <username>@<storage_server_ip>:/usr/src/kodekloudrepos/apps/
Replace and with actual values.
🔐 Step 2: SSH into the Storage Server
Once the file is copied, log into the storage server:
ssh <username>@<storage_server_ip>
📂 Step 3: Navigate to the Git Repository
Change into the project directory where the Git repo is cloned:
cd /usr/src/kodekloudrepos/apps
Double-check the file is there:
ls -l index.html
📝 Step 4: Add and Commit the File to Git
Now stage and commit the file:
git add index.html
git commit -m "Add sample index.html file"
🚀 Step 5: Push the Commit to the Remote Repository
Push the change to the master branch:
git push origin master
🚨 Common Error: index.lock Permission Denied
You might run into this error:
fatal: Unable to create '/usr/src/kodekloudrepos/apps/.git/index.lock': Permission denied
This happens when your user doesn’t have permission to modify the Git repo. Here’s how to fix it.
🛠️ Step 6: Fixing Git Permission Error
✅ Option 1: Use sudo (Quick Fix)
sudo git add index.html
sudo git commit -m "Add sample index.html file"
sudo git push origin master
🧼 Option 2: Change Ownership (Recommended)
If you're supposed to manage this repo long-term:
sudo chown -R $(whoami):$(whoami) /usr/src/kodekloudrepos/apps
Then you can use Git without sudo
.
👤 Option 3: Switch to Root (One-time Fix)
If the repo should stay owned by root:
sudo su - root
cd /usr/src/kodekloudrepos/apps
git add index.html
git commit -m "Add sample index.html file"
git push origin master
✅ Final Verification
Run this to make sure the file is tracked and pushed:
git status
git log --oneline
💬 Got stuck somewhere?
Drop a comment with the exact error or step, and let’s debug it together. This kind of real-world Git workflow is foundational in any DevOps role — and mastering it makes your life easier every time.
Top comments (0)