In a bid to automate backup processes, the xFusionCorp Industries sysadmin team has developed a new bash script named xfusioncorp.sh. While the script has been distributed to all necessary servers, it lacks executable permissions on App Server 2 within the Stratos Datacenter.
Your task is to grant executable permissions to the /tmp/xfusioncorp.sh script on App Server 2. Additionally, ensure that all users have the capability to execute it.
Solution
Step 1: Connect to App Server 2 (stapp02)
ssh steve@stapp02
# Password: Am3ric@
Step 2: Switch to root or use sudo
sudo su -
# Password: Am3ric@
Step 3: Check current permissions
ls -la /tmp/xfusioncorp.sh
Step 4: Grant executable permissions to all users
chmod a+x /tmp/xfusioncorp.sh
Command breakdown:
-
chmod: Change file permissions -
a+x: Add execute permission for all users (owner, group, others)-
a= all users -
+= add permission -
x= execute permission
-
Alternative approaches:
# Using numeric mode (755 gives rwxr-xr-x)
chmod 755 /tmp/xfusioncorp.sh
# Using symbolic mode (same as a+x)
chmod +x /tmp/xfusioncorp.sh
# Explicitly for all users
chmod u+x,g+x,o+x /tmp/xfusioncorp.sh
Step 5: Verify the permissions
ls -la /tmp/xfusioncorp.sh
# Should show: -rwxr-xr-x or -rwxr-xr-x
# Verify all users can execute
# As root, test execution
/tmp/xfusioncorp.sh
# As another user (if exists)
su - steve -c "/tmp/xfusioncorp.sh"
Complete One-Line Commands
From jump host with password:
echo 'Am3ric@' | ssh steve@stapp02 "sudo -S chmod a+x /tmp/xfusioncorp.sh && sudo -S ls -la /tmp/xfusioncorp.sh"
From jump host using heredoc:
ssh steve@stapp02 << 'EOF'
echo 'Am3ric@' | sudo -S bash -c '
echo "Current permissions:"
ls -la /tmp/xfusioncorp.sh
echo ""
echo "Adding execute permissions for all users..."
chmod a+x /tmp/xfusioncorp.sh
echo ""
echo "Updated permissions:"
ls -la /tmp/xfusioncorp.sh
echo ""
echo "✓ Execute permission granted successfully"
'
EOF
Step-by-Step Interactive Commands
# Connect to stapp02
ssh steve@stapp02
# Enter password: Am3ric@
# Become root
sudo su -
# Enter password: Am3ric@
# Check current permissions
ls -la /tmp/xfusioncorp.sh
# Example output before:
# -rw-r--r-- 1 root root 1024 Jul 03 10:00 /tmp/xfusioncorp.sh
# (No execute permissions)
# Add execute permissions for all users
chmod a+x /tmp/xfusioncorp.sh
# Verify permissions
ls -la /tmp/xfusioncorp.sh
# Expected output after:
# -rwxr-xr-x 1 root root 1024 Jul 03 10:00 /tmp/xfusioncorp.sh
# (Execute permissions for all)
# Test execution
/tmp/xfusioncorp.sh
# Exit back
exit
exit
Permission Breakdown
Understanding the permissions:
| Mode | Owner | Group | Others | Description |
|---|---|---|---|---|
Before: -rw-r--r--
|
Read/Write | Read | Read | No execute permission |
After: -rwxr-xr-x
|
Read/Write/Execute | Read/Execute | Read/Execute | Execute permission for all |
Various chmod options:
# Add execute for all (same as a+x)
chmod +x /tmp/xfusioncorp.sh
# Add execute for owner only
chmod u+x /tmp/xfusioncorp.sh
# Add execute for group only
chmod g+x /tmp/xfusioncorp.sh
# Add execute for others only
chmod o+x /tmp/xfusioncorp.sh
# Remove execute for all
chmod a-x /tmp/xfusioncorp.sh
# Set exact permissions (755 = rwxr-xr-x)
chmod 755 /tmp/xfusioncorp.sh
# Set exact permissions (777 = rwxrwxrwx)
chmod 777 /tmp/xfusioncorp.sh
Verification Commands
Run these to verify everything is correct:
# 1. Check permissions
ls -la /tmp/xfusioncorp.sh
# 2. Check file type and permissions in detail
stat /tmp/xfusioncorp.sh
# 3. Verify it's executable by owner
test -x /tmp/xfusioncorp.sh && echo "✓ Executable by owner" || echo "✗ Not executable by owner"
# 4. Check if executable by all users
# As current user
/tmp/xfusioncorp.sh
# Check if others can execute (if another user exists)
sudo -u steve /tmp/xfusioncorp.sh
# 5. Get octal permissions
stat -c "%a %n" /tmp/xfusioncorp.sh
# Should output: 755 /tmp/xfusioncorp.sh or 755
# 6. Check script content
cat /tmp/xfusioncorp.sh
# 7. Verify script syntax
bash -n /tmp/xfusioncorp.sh
Expected Output
[root@stapp02 ~]# ls -la /tmp/xfusioncorp.sh
-rw-r--r-- 1 root root 1024 Jul 03 10:00 /tmp/xfusioncorp.sh
[root@stapp02 ~]# chmod a+x /tmp/xfusioncorp.sh
[root@stapp02 ~]# ls -la /tmp/xfusioncorp.sh
-rwxr-xr-x 1 root root 1024 Jul 03 10:00 /tmp/xfusioncorp.sh
[root@stapp02 ~]# /tmp/xfusioncorp.sh
[Script output...]
[root@stapp02 ~]# stat -c "%a %n" /tmp/xfusioncorp.sh
755 /tmp/xfusioncorp.sh
Troubleshooting
- "No such file or directory":
# Check if script exists
ls -la /tmp/xfusioncorp.sh
# If not, check alternative locations
find /tmp -name "xfusioncorp.sh" 2>/dev/null
- "Permission denied" when changing permissions:
# Use sudo to gain required permissions
sudo chmod a+x /tmp/xfusioncorp.sh
# Or become root
sudo su -
- Script doesn't execute even with permissions:
# Check if script has correct shebang
head -1 /tmp/xfusioncorp.sh
# Should be: #!/bin/bash or similar
# Run with bash explicitly
bash /tmp/xfusioncorp.sh
- Need to preserve other permissions:
# Only add execute, don't change read/write
chmod a+x /tmp/xfusioncorp.sh
Additional Security Considerations
Less permissive approaches (if required):
# Owner can execute only
chmod u+x /tmp/xfusioncorp.sh
chmod go-x /tmp/xfusioncorp.sh
# Result: -rwxr--r--
# Owner and group can execute
chmod u+x,g+x /tmp/xfusioncorp.sh
chmod o-x /tmp/xfusioncorp.sh
# Result: -rwxr-xr--
Verify script safety:
# Check script content
cat /tmp/xfusioncorp.sh
# Check for suspicious commands
grep -E "(rm -rf|dd|mkfs|>/dev)" /tmp/xfusioncorp.sh
# Test script in safe mode
bash -n /tmp/xfusioncorp.sh # Syntax check
bash -x /tmp/xfusioncorp.sh # Debug mode
Complete Solution Summary
The task has been completed on App Server 2 (stapp02):
- ✅ Script located at
/tmp/xfusioncorp.sh - ✅ Execute permissions added for all users (
chmod a+x) - ✅ Permissions changed from
-rw-r--r--to-rwxr-xr-x - ✅ Verified script is executable by all users
- ✅ Script can now be executed by any user on the system
The bash script xfusioncorp.sh is now ready for use in the automated backup processes as required by the xFusionCorp Industries sysadmin team.
Top comments (0)