يحتوي macOS على خادم OpenSSH مدمج — معطّل افتراضيًا. تشغيله يتطلب تبديلًا واحدًا، لكن الإعداد المناسب للإنتاج يتضمن مفاتيح وإعدادًا محصّنًا.
المتطلبات المسبقة
- macOS 12 Monterey أو أحدث، حساب admin.
- مفتاح Ed25519 على محطة عملك.
الخطوة 1: تمكين Remote Login
sudo systemsetup -setremotelogin on
sudo systemsetup -getremotelogin
الخطوة 2: ادفع مفتاح SSH
ssh-copy-id you@mac.local
ssh -o PasswordAuthentication=no you@mac.local whoami
الخطوة 3: تحصين sshd_config
/etc/ssh/sshd_config.d/99-skyline.conf:
PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes
MaxAuthTries 3
LoginGraceTime 30
أعد تحميل sshd:
sudo /usr/sbin/sshd -t
sudo systemsetup -setremotelogin off
sudo systemsetup -setremotelogin on
الخطوة 4: تقييد من يمكنه SSH
sudo dseditgroup -o create -q com.apple.access_ssh
sudo dseditgroup -o edit -a yourusername -t user com.apple.access_ssh
الخطوة 5: نقل SSH عن المنفذ 22
Port 2222
الخطوة 6: تكوين SSH للاستخدام اليومي
~/.ssh/config:
Host mac
HostName mac.local
User ops
Port 2222
IdentityFile ~/.ssh/id_ed25519
التحقق
sudo /usr/sbin/sshd -t
sudo log show --predicate 'process == "sshd"' --last 1h | tail -20
الخاتمة
OpenSSH على macOS هو نفس الخادم على Linux مع نظام إعادة تحميل مختلف (launchd).
Comments
0 total · 0 threads