A person can endure hardship, but two cannot; otherwise, one might think the hardship is caused by the other.

Introduction
A security incident report from a major cloud provider last year indicated that over 40% of system intrusions began with incorrect permission configurations. Just last month, I personally experienced such a crisis—a seemingly simple SSH login failure that ultimately evolved into a deep exploration of the Linux permission system.
Einstein once said, “In crisis, there is the greatest opportunity.” That 2 AM failure notification not only tested my technical abilities but also led me to a renewed understanding of the philosophical wisdom behind Linux permission design.
When <span>Permission denied (publickey)</span> meets <span>user is not in the sudoers file</span>, it is not just two error messages, but an important signal from the Linux security model.
Act One: The Maze of SSH Login Permissions
Failure Phenomenon
ssh [email protected]
# Permission denied (publickey)
Thought Process of an Ordinary Engineer
- “Is there a network issue?”
- “Is the firewall blocking it?”
- “Is the key configuration wrong?”
- Try various random fixes
Systematic Troubleshooting by a Senior Engineer
Hierarchical Diagnostic Framework:
- Network Layer Verification:
telnet 47.100.178.111 22
# Confirm port reachability
traceroute 47.100.178.111
# Network path check
- Service Layer Check:
# Check SSH service status on the server
systemctl status sshd
netstat -tlnp | grep :22
- Permission Layer Deep Analysis:
# Check directory permission chain
name="phray"
echo "Home directory permissions:"
ls -ld /home/$name
echo "SSH directory permissions:"
ls -ld /home/$name/.ssh
echo "Key file permissions:"
ls -l /home/$name/.ssh/authorized_keys
echo "File owner:"
stat -c "%U:%G" /home/$name/.ssh/authorized_keys
Philosophical Insights on Permission Design
The strict requirements of SSH permissions reflect the security boundary philosophy of Linux:
- Each level has a clear permission boundary
- Cross-boundary access requires explicit authorization
- Default deny is better than default allow
Act Two: In-Depth Exploration of Sudo Permissions
New Challenges
After successfully logging in, urgent security updates are needed:
sudo apt update
# phray is not in the sudoers file. This incident will be reported.
The Ingenious Design of the Sudoers System
Ordinary Fix:
# Dangerous heavy-handed approach
usermod -aG sudo phray
Expert-Level Fix:
# 1. Use visudo to prevent syntax errors
sudo visudo -f /etc/sudoers.d/phray-sudo
# 2. Principle of least privilege configuration
# phray can only execute specific package management commands
phray ALL=(root) /usr/bin/apt, /usr/bin/apt-get, /usr/bin/dpkg
The Four-Layer Protection System of Sudo Permissions
- User Authentication Layer: Verifies user identity
- Command Limitation Layer: Controls executable commands
- Identity Switching Layer: Controls switchable identities
- Environment Isolation Layer: Controls environment variable inheritance
Act Three: A Unified Philosophy of Permission Management
The Three Pillars of the Linux Permission Model
1. Discretionary Access Control (DAC)
# Traditional Unix permission model
rwxr-x--- # Separation of user, group, and others' permissions
2. Capabilities
# Fine-grained privilege control
setcap 'cap_net_bind_service=+ep' /usr/bin/myapp
3. Mandatory Access Control (MAC)
# Additional protection layer provided by SELinux/AppArmor
semanage fcontext -a -t httpd_sys_content_t "/webapp(/.*)?"
Systematic Permission Audit Framework
Permission Health Check Checklist:
#!/bin/bash
# permission-audit.sh
USERNAME="phray"
echo "=== Comprehensive User Permission Audit ==="
echo "1. Basic user information:"
id $USERNAME
echo -e "\n2. Group membership:"
groups $USERNAME
echo -e "\n3. File permission checks:"
echo "Home directory: $(ls -ld /home/$USERNAME)"
[-d /home/$USERNAME/.ssh ] && echo "SSH directory: $(ls -ld /home/$USERNAME/.ssh)"
[-f /home/$USERNAME/.ssh/authorized_keys ] && echo "Authorized key: $(ls -l /home/$USERNAME/.ssh/authorized_keys)"
echo -e "\n4. Sudo permissions:"
sudo -l -U $USERNAME 2>/dev/null || echo "No sudo permissions"
echo -e "\n5. Special permission files:"
find / -user $USERNAME -perm -4000 -ls 2>/dev/null
Act Four: Upgrading Thinking from Failure to Architecture
Differences in Thinking Between Ordinary Engineers and Senior Engineers
| Dimension | Ordinary Engineer | Senior Engineer |
|---|---|---|
| Problem Perspective | Sees error messages | Sees system design |
| Solution Approach | Trial fixes | Systematic troubleshooting |
| Time Allocation | 80% trial, 20% thinking | 20% trial, 80% thinking |
| Outcome Output | Solves current problem | Establishes preventive system |
Best Practices for Building Permission Management
1. Infrastructure as Code (IaC)
# Use Ansible to manage permissions
- name: Configure user permissions
user:
name: phray
groups: developers
append: yes
- name: Configure sudo permissions
copy:
content: |
phray ALL=(ALL) /usr/bin/apt, /usr/bin/systemctl
dest: /etc/sudoers.d/phray
mode: 0440
2. Standardization of Golden Images
# Standard permission configurations included in base images
# Ensure consistent permissions across all instances
3. Continuous Audit Monitoring
# Regular permission audits
#!/bin/bash
# Monitor permission changes
find /etc/sudoers* -mtime -1 -ls
In-Depth Summary: The Art and Science of Permission Management
That early morning failure was ultimately resolved through systematic permission auditing and precise fixes. However, the true value lies not in solving the problem but in establishing a deep understanding of the Linux permission system.
Three Core Cognitive Upgrades:
-
From Commands to Philosophy: Linux permissions are not just a collection of commands but a complete security philosophy system
-
From Isolation to System: Every permission issue is not isolated but a reflection of the overall system security state
-
From Reactive to Proactive: Transitioning from passive responses to failures to actively building a security system
The concept of “Shen Du” (慎独) from Zeng Guofan is particularly important in permission management: even without supervision, permissions should be configured to the highest standards, as true security comes from daily rigor rather than emergency remedies.
If there are any issues, feel free to contact me at:
- My homepage: https://todzhang.com/
- Email: [email protected]