mcpField
L
linux-administration

linux-administration

github.com/bagelholeクラウド・DevOps1.2k782 回インストール23 週間前に更新
リポジトリ

linux-administration について

Debian/Ubuntu、RHEL/CentOS のサーバーや開発環境を管理する運用担当者向けの Linux 管理スキルです。日常的なシステム管理とコマンドによるトラブルシューティングを扱います。

主な機能

  1. 01パッケージの導入と更新
  2. 02ファイルシステムとディスク管理
  3. 03プロセスとリソースの確認
  4. 04Cron と systemd タイマーの設定
  5. 05ログ分析とネットワーク確認

活用シーン

  1. 01Linux サーバーの保守
  2. 02ディスク枯渇や CPU 高負荷の調査
  3. 03定期メンテナンスのスケジュール設定
  4. 04サービス起動失敗の調査

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/bagelhole/devops-security-agent-skills --skill linux-administration

インストール後、Claude Code で/linux-administrationを入力して読み込まれたか確認します。

詳細

Linux 管理

Debian/Ubuntu および RHEL/CentOS ディストリビューションの本番サーバー、開発環境、インフラストラクチャホストを管理するための、Linux システム管理の基本的なスキルです。

使用する場面

  • あらゆる環境で Linux サーバーをプロビジョニングおよび保守する
  • ソフトウェアパッケージをインストール、更新、削除する
  • ファイルシステム、ディスク使用量、マウントポイントを管理する
  • 暴走プロセスやリソースの過剰な消費を調査する
  • cron または systemd タイマーで定期タスクをスケジュールする
  • トラブルシューティングのためにシステムログやアプリケーションログを分析する

前提条件

  • 対象システムの root または sudo アクセス
  • SSH アクセスが設定済みであること(ssh-configuration スキルを参照)
  • ターミナルテキストエディター(vim、nano)の使用経験
  • パッケージマネージャーが利用可能であること(Debian/Ubuntu では apt、RHEL 8+/Fedora では dnf)

パッケージ管理

Debian / Ubuntu(apt)
# Update package index and upgrade all installed packages
apt update && apt upgrade -y

# Search for a package by keyword
apt search nginx

# Show detailed package info including dependencies
apt show nginx

# Install a specific version of a package
apt install nginx=1.24.0-1ubuntu1

# Install multiple packages in one command
apt install -y nginx certbot python3-certbot-nginx

# Remove a package but keep its config files
apt remove nginx

# Remove a package and purge all config files
apt purge nginx

# Remove unused dependency packages
apt autoremove -y

# List all installed packages
dpkg -l | grep nginx

# Pin a package to prevent automatic upgrades
cat <<'EOF' > /etc/apt/preferences.d/pin-nginx
Package: nginx
Pin: version 1.24.0-1ubuntu1
Pin-Priority: 1001
EOF

# Add an external repository (example: Docker CE)
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" \
  > /etc/apt/sources.list.d/docker.list
apt update
RHEL / CentOS / Fedora(dnf)
# Update all packages
dnf update -y

# Search for a package
dnf search nginx

# Show package details
dnf info nginx

# Install a package
dnf install -y nginx

# Install a specific version
dnf install nginx-1.24.0-1.el9

# Remove a package
dnf remove nginx

# List installed packages
dnf list installed | grep nginx

# Enable a module stream (example: Node.js 20)
dnf module enable nodejs:20
dnf install -y nodejs

# Add an external repository
dnf install -y epel-release

# View repository list
dnf repolist --all

# Clean cached package data
dnf clean all

システム情報

# Kernel and OS release
uname -a
cat /etc/os-release

# Hostname and system metadata
hostnamectl

# CPU information
lscpu
nproc                      # Number of processing units

# Memory usage (human-readable)
free -h

# Disk usage summary
df -hT                     # Include filesystem type
du -sh /var/log/*          # Summarize directory sizes

# Network interfaces and IP addresses
ip addr show
ip route show              # Routing table

# Uptime and load average
uptime
w                          # Who is logged in and load

ファイルシステム管理

# List block devices and partitions
lsblk
fdisk -l

# Create a new ext4 filesystem on a partition
mkfs.ext4 /dev/sdb1

# Mount a filesystem temporarily
mount /dev/sdb1 /mnt/data

# Add a persistent mount via fstab
echo '/dev/sdb1  /mnt/data  ext4  defaults,noatime  0  2' >> /etc/fstab
mount -a                   # Mount everything in fstab

# Check and repair a filesystem (unmount first)
umount /dev/sdb1
fsck.ext4 -y /dev/sdb1

# Monitor disk I/O in real time
iostat -xz 2

# Find files larger than 100 MB
find / -xdev -type f -size +100M -exec ls -lh {} \;

# Check inode usage (out-of-inodes can mimic out-of-disk)
df -i

プロセス管理

# List all processes with full details
ps auxf

# Interactive process viewer (prefer htop if installed)
top
htop

# Find processes by name
pgrep -la nginx

# Show process tree
pstree -p

# Send graceful stop signal (SIGTERM)
kill <pid>

# Force kill an unresponsive process (SIGKILL)
kill -9 <pid>

# Kill all processes matching a name
pkill nginx

# Show open files for a process
lsof -p <pid>

# Show which process is listening on a port
ss -tlnp | grep :80
lsof -i :80

# Run a process immune to hangups (persists after logout)
nohup /opt/myapp/start.sh > /var/log/myapp.log 2>&1 &

# Limit CPU usage of a running process with cgroups v2
systemd-run --scope -p CPUQuota=25% --unit=limit-myapp /opt/myapp/start.sh

cron ジョブ管理

# Edit the current user's crontab
crontab -e

# List current user's cron jobs
crontab -l

# Example crontab entries
# ┌───── minute (0-59)
# │ ┌───── hour (0-23)
# │ │ ┌───── day of month (1-31)
# │ │ │ ┌───── month (1-12)
# │ │ │ │ ┌───── day of week (0-7, 0 and 7 = Sunday)
# * * * * * command

# Run a backup every day at 2:30 AM
30 2 * * * /usr/local/bin/backup.sh >> /var/log/backup.log 2>&1

# Run a cleanup every Sunday at midnight
0 0 * * 0 /usr/local/bin/cleanup.sh

# Run a health check every 5 minutes
*/5 * * * * /usr/local/bin/healthcheck.sh

# Place system-wide cron scripts in drop-in directories
ls /etc/cron.daily/
ls /etc/cron.weekly/

# Restrict cron access to specific users
echo "deploy" >> /etc/cron.allow

ログ管理

# Follow systemd journal for a specific service
journalctl -u nginx -f

# Show logs since last boot
journalctl -b

# Show logs from a specific time range
journalctl --since "2025-01-15 08:00" --until "2025-01-15 12:00"

# Show only error-level and above
journalctl -p err

# Tail traditional syslog
tail -f /var/log/syslog          # Debian/Ubuntu
tail -f /var/log/messages        # RHEL/CentOS

# Kernel ring buffer messages
dmesg -T                          # Human-readable timestamps
dmesg --level=err,warn

# Check disk usage of log directory
du -sh /var/log/*

# Configure logrotate for a custom application
cat <<'EOF' > /etc/logrotate.d/myapp
/var/log/myapp/*.log {
    daily
    missingok
    rotate 14
    compress
    delaycompress
    notifempty
    create 0640 myapp myapp
    sharedscripts
    postrotate
        systemctl reload myapp > /dev/null 2>&1 || true
    endscript
}
EOF

# Force a logrotate run for testing
logrotate -f /etc/logrotate.d/myapp

# Centralized logging: forward journal to a remote syslog
# In /etc/systemd/journal-upload.conf:
# URL=http://logserver.example.com:19532

ネットワークの基本

# Test connectivity
ping -c 4 8.8.8.8

# DNS lookup
dig example.com
nslookup example.com

# Trace route to host
traceroute example.com

# List listening ports and associated processes
ss -tlnp

# Show active connections
ss -tunap

# Firewall management (UFW on Ubuntu)
ufw allow 22/tcp
ufw allow 80/tcp
ufw allow 443/tcp
ufw enable
ufw status verbose

# Firewall management (firewalld on RHEL/CentOS)
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload
firewall-cmd --list-all

トラブルシューティング

症状診断コマンド一般的な対処方法
ディスクが満杯df -h and du -sh /var/log/*古いログを消去し、logrotate -f を実行して、一時ファイルを削除する
inode が不足df -i小さなファイルを大量に削除し、/tmp とメールスプールを確認する
CPU 使用率が高いtop, ps aux --sort=-%cpu問題のプロセスを特定し、再起動または終了する
メモリ不足/スワップ発生free -h, vmstat 1vm.swappiness を調整し、RAM を増設して、メモリリークを特定する
サービスが起動しないsystemctl status <svc>, journalctl -u <svc>設定構文、ファイル権限、ポートの競合を確認する
DNS 名前解決に失敗するdig @8.8.8.8 example.com, cat /etc/resolv.confネームサーバーのエントリーを修正し、systemd-resolved を再起動する
パッケージの依存関係エラーapt --fix-broken install or dnf distro-sync保留中または競合するパッケージを解決する
SSH 接続が拒否されるss -tlnp | grep 22, systemctl status sshdsshd が実行中で、ファイアウォールがポート 22 を許可していることを確認する

関連スキル

  • ssh-configuration -- Linux サーバーへの安全なリモートアクセス
  • user-management -- ユーザー、グループ、sudo の作成と管理
  • systemd-services -- systemd ユニットファイルの作成と管理
  • performance-tuning -- カーネルとアプリケーションのパフォーマンス最適化
  • backup-recovery -- 自動バックアップによるサーバーデータの保護

コメント