ITCS 310 · Network Security · Week 09
Secure Shell Protocol (SSH)
بروتوكول القشرة الآمنة (SSH)
Transport Layer Security Remote Access Key Exchange ملزمة ثنائية اللغة
ACADEZI.COM
College of Information Technology
Detailed Teaching Guide · دليل تدريس مفصّل
لماذا نحتاج إلى الوصول لجهاز عن بُعد؟ (Motivation) Why We Need to Access a Remote Device? §1
هناك عدة أسباب تدفعنا للحاجة للوصول إلى أجهزة عن بُعد (مثل الأجهزة في مراكز البيانات Data Centers) دون التواجد الفعلي أمامها :
There are several reasons we need to access remote devices (e.g., in Data Centers) without physically being in front of them :
1
استكشاف أخطاء الشبكة
Troubleshooting network connectivity
اختبار الاتصال بجهاز شبكة أو خادم، والتأكد من إمكانية الوصول إليه، وتحديد أي أخطاء، وتشخيص المشاكل .
Test connectivity, check if device is reachable, identify errors, and diagnose network problems .
2
إعداد أجهزة الشبكة
Configuring network devices
إعداد أجهزة التوجيه (Routers)، والمحولات (Switches)، والجدران النارية (Firewalls) دون الوصول المادي للجهاز .
Configure routers, switches, and firewalls without physically accessing the device .
3
الإدارة عن بُعد للخوادم
Remote administration of servers
إدارة الخوادم وإعدادها عن بُعد عبر واجهة سطر الأوامر (CLI)، تشغيل السكربتات، وتنفيذ مهام أخرى .
Administer servers running a command-line interface, manage configs, run scripts, and perform other tasks .
4
اختبار وتصحيح التطبيقات
Testing and debugging applications
استخدام البروتوكولات للتحقق مما إذا كان التطبيق يستطيع الاتصال والتواصل مع خادم أو جهاز عن بُعد .
Use protocols to check whether an app can connect and communicate with a remote server/device .
أكثر بروتوكولات الوصول عن بُعد شيوعاً (Telnet vs SSH) Remote Access: The Two Most Popular Protocols §2
للوصول بنجاح إلى جهاز عن بُعد، نحتاج إلى بيانات اعتماد/مصادقة (Credentials) مثل اسم المستخدم وكلمة المرور . إرسال هذه البيانات عبر شبكة عامة بطريقة غير آمنة يمثل خطراً كبيراً؛ حيث يمكن للمهاجم الحصول عليها والحصول على نفس صلاحيات إدارة وتكوين النظام .
To successfully access a remote device, authentication tokens/credentials (like username and password) are required . Sending these over a public unsecured network is a great risk, as adversaries could obtain them and gain administrative privileges .
Telnet Protocol
بروتوكول Telnet (غير آمن)
يتم الاتصال بين العميل والخادم في هيئة نص واضح (Plaintext) عبر المنفذ 23 . بيانات الاعتماد (اسم المستخدم وكلمة المرور) تُرسل بدون تشفير ويمكن لأي شخص يعترض الاتصال قراءتها بوضوح .
Communication between client and server is in plaintext over Port 23 . User credentials are sent unencrypted and can be read by anyone intercepting the communication .
Secure Shell (SSH) Protocol
بروتوكول القشرة الآمنة (SSH)
جاء كبديل لـ Telnet . يتم الاتصال بصورة آمنة (Secured) عبر المنفذ 22 . بيانات الاعتماد تُرسل مشفرة ولا يمكن للمهاجمين الذين يعترضون الاتصال قراءتها .
A replacement for Telnet . Communication is secured over Port 22 . Credentials are encrypted and cannot be read by adversaries .
ملاحظة: هناك بروتوكولات أخرى للوصول عن بُعد مثل rlogin (remote login) و rsh (remote shell) .
Note: Other remote access protocols include rlogin and rsh .
ما هو بروتوكول SSH؟ (التفاصيل والبرامج) SSH Details & Implementations §3
SSH هو بروتوكول شبكة تشفيري للعمل بأمان عبر شبكة غير آمنة . أبرز تطبيقاته هي تسجيل الدخول عن بُعد (Remote login) وتنفيذ سطر الأوامر .
الإصدار الأول (SSH-1) كان عرضة للثغرات وهو الآن مُهمل (Deprecated)، بينما (SSH-2) يُستخدم حالياً على نطاق واسع ويقدم أماناً مُحسناً وتشفيراً أقوى .
SSH is a cryptographic network protocol for operating securely over an unsecured network . Notable applications include remote login and command-line execution . SSH-1 is deprecated due to flaws, while SSH-2 is widely used today with enhanced security and stronger encryption .
SSH Client & Server
عميل وخادم SSH
عميل SSH (Client): برنامج يستخدم البروتوكول للاتصال بجهاز بعيد .
خادم SSH (Server): برنامج يستخدم البروتوكول لقبول الاتصالات من الأجهزة البعيدة .
SSH Client: A program that uses SSH to connect to a remote device .
SSH Server: A program that accepts connections from remote computers .
المراحل الرئيسية لبروتوكول SSH (نظرة عامة) SSH Protocol Overview - Main Stages §4
يمر بروتوكول SSH بخمس مراحل رئيسية لتأسيس اتصال آمن ومُصادق عليه :
The SSH protocol goes through 5 main stages to establish a secure, authenticated connection :
المرحلة Stage الوصف والخطوات الفرعية Description & Sub-steps
1. TCP Handshakeمصافحة TCP تأسيس الاتصال الأساسي عبر بروتوكول TCP (SYN, SYN+ACK, ACK) .Establish basic connection over TCP .
2. Identification String Exchangeتبادل سلسلة الهوية تبادل الإصدارات (نسخة بروتوكول SSH، نسخة البرنامج المُستخدم) .Versions exchange [SSH Protocol version, Software version] .
3. Algorithms Negotiationsالتفاوض على الخوارزميات يتم الاتفاق على الخوارزميات لـ: 1) تبادل المفاتيح (مثل DH, ECDH)، 2) التشفير (متماثل: AES, 3DES / غير متماثل: RSA, DSA, ECDSA)، 3) الهاش MAC (مثل SHA-1, SHA-2, MD5)، 4) الضغط (Compression) .Negotiate algorithms for: 1. Key exchange, 2. Encryption (Symmetric/Asymmetric), 3. MAC (hash), 4. Compression .
4. Key Exchange and Server Authتبادل المفاتيح ومصادقة الخادم توليد سر مشترك ومصادقة هوية المضيف (الخادم) Host Authentication .Generate shared secret and perform Host Authentication .
5. Service Request & Session Initطلب الخدمة وبدء الجلسة يطلب العميل المصادقة (Client Authentication) باستخدام كلمة مرور (Password) أو أزواج المفاتيح (Public/private key pairs)، ثم تبدأ الجلسة الآمنة .Client Authentication via Password or Public/private key pairs, followed by secure session initiation .
المرحلة 3: التفاوض على الخوارزميات (Algorithms Negotiations) Stage 3: Algorithms Negotiations §5
C. KEXINT: العميل يرسل قائمة بالخوارزميات التي يدعمها مُرتبة حسب الأفضلية . S. KEXINT: الخادم يرسل قائمة بالخوارزميات التي يدعمها . كلاهما يخمن خوارزميات الآخر . إذا فشل التخمين، يختار الخادم الخيار الأول من قائمة العميل إذا كان مدعوماً لديه . إذا لم يتمكنا من الاتفاق، يفشل الاتصال ويفصلان .
C. KEXINT: Client sends list of supported algorithms ordered by preference . S. KEXINT: Server sends its supported list . Both guess each other's algorithms . If guess fails, server picks the first choice from client's preference if supported . If they cannot agree, connection fails and disconnects .
المرحلة 4: خطوات تبادل المفاتيح (Key Exchange - Detailed Steps) Stage 4: Key Exchange - Detailed Steps §6
هذه المرحلة حاسمة لتوليد المفاتيح الآمنة والتأكد من هوية الخادم . تتكون من 8 خطوات رئيسية :
This stage is crucial for generating secure keys and authenticating the server . It consists of 8 detailed steps :
1
يولد العميل زوج مفاتيح (Key pair) لاستخدامها في Diffie-Hellman، ويرسل المفتاح العام للـ DF (C. DF Pub. Key) إلى الخادم .
Client generates a key pair for Diffie-Hellman and sends the DF Public Key to the server .
2
يولد الخادم زوج مفاتيح DF الخاص به. الآن يمتلك الخادم (مفتاح DF العام للعميل، مفتاح DF العام للخادم، ومفتاح DF الخاص للخادم) ويستخدمها لتوليد مفتاح سري مشترك (Shared Secret Key) .
Server generates its DF key pair. Having client's public DF key and its own pair, it generates a Shared Secret Key .
3
يولد الخادم هاش مُتبادل (Exchanged Hash) باستخدام 8 مكونات كمدخلات لدالة الهاش المتفق عليها (منها: المفاتيح العامة للطرفين، المفتاح السري، وسلاسل الهوية) .
Server generates an Exchanged Hash using 8 components as input to the agreed hash function .
4
يُوقّع (Signs) الخادم هذا الهاش المتبادل باستخدام المفتاح الخاص للخادم (Server's Private Key) . (هذا يُثبت هويته للعميل ).
Server signs the exchanged hash with its Private Key . (This proves its identity to the client ).
5
يرسل الخادم للعميل: (الهاش الموقع، مفتاح DF العام للخادم، المفتاح العام للخادم) .
Server sends to client: Signed exchanged hash, Server's DF Public Key, Server's Public Key .
6
العميل يولد الهاش المتبادل الخاص به (لأنه يمتلك الآن نفس المكونات الثمانية) .
Client generates its own exchanged hash (it now has all 8 components) .
7
يتحقق (Verifies) العميل من مفتاح الخادم العام. ثم يستخدمه لفك تشفير الهاش المُستلم . إذا تطابق الهاش المفكوك مع الذي ولّده العميل في خطوة 6، يتم مصادقة الخادم بنجاح .
Client verifies Server's Public Key, then uses it to decrypt the received hash . If it matches the client's generated hash, the server is authenticated .
8
يستخدم الطرفان المفتاح السري المشترك كقاعدة لتوليد ستة مفاتيح جديدة (Six New Keys) (2 للتشفير، 2 للـ IV، 2 للنزاهة Integrity) للاتصالات المستقبلية ويتم تبادل إشارة بدء استخدامها .
Both use the shared secret to generate Six New Keys (2 encryption, 2 IV, 2 integrity) for future communication and signal to start using them .
التحقق من المفتاح العام للخادم (من قبل العميل) Server's Public Key Verification - By the Client §7
أثناء الخطوة 7 في تبادل المفاتيح، يحتاج العميل للتحقق من المفتاح العام المُرسل من الخادم .
During Step 7 of key exchange, the client needs to verify the Public Key sent by the server .
يفحص العميل ما إذا كان يمتلك هذا المفتاح مسبقاً (من اتصالات سابقة)، أو يتحقق عبر مرجع شهادات (Certificate Authority) . إذا لم يتوفر أي منهما، الأمر متروك للعميل لقبول المفتاح دون تحقق .

هذا هو سبب ظهور رسالة التحذير (Security Alert) في برامج مثل PuTTY ("The server's host key is not cached in the registry") . إذا اختار المستخدم "نعم (Yes)"، فهو يقبل المفتاح ويثق بالخادم، ويتم حفظ المفتاح محلياً لتجنب الرسالة في المرات القادمة .
The client checks if it had the key earlier or checks with a CA . If neither exists, it's up to the client to accept the public key without verification .

This is why warning messages appear in tools like PuTTY ("The server's host key is not cached...") . Answering 'Yes' means accepting and trusting the host, and saving the key locally for direct connections next time .
المرحلة 5: طلب الخدمة (Service Request) والمصادقة Stage 5: Service Request & Authentication §8
بعد تبادل المفاتيح وتأسيس القناة المشفرة، يرسل العميل طلب خدمة للمصادقة (SSH_MSG_SERVICE_REQUEST) . ويرد الخادم بالموافقة . بمجرد تأسيس الجلسة الآمنة، يُقدم العميل بيانات الاعتماد (Credentials) لتسجيل الدخول عبر هذه القناة المشفرة .
After key exchange, the client sends a service request for user authentication (SSH_MSG_SERVICE_REQUEST) . Server responds with accept . A secure session gets established and the client provides credentials to log in through this encrypted channel .
طرق مصافحة ومصادقة العميل (Client Authentication Methods) SSH Authentication Methods §9
Password Auth
عبر كلمة المرور
أبسط طريقة (اسم وكلمة مرور). غير مفضلة في البيئات عالية الأمان لأنها عُرضة لهجمات Brute-force .
Simplest method (user/pass). Not recommended for high-security environments due to brute-force risks .
Public-Private Key
أزواج المفاتيح (مُفضل)
يستخدم أزواج مفاتيح تشفير. المفتاح الخاص يبقى مع العميل، والعام يوضع على الخادم. آمنة جداً ومثالية لتسجيل الدخول الآلي بدون كلمة مرور .
Uses cryptographic key pairs. Private key stays with client, public on server. Highly secure, ideal for passwordless login and automation .
Two-Factor (2FA)
المصادقة الثنائية
طبقة أمان إضافية تتطلب رمزاً لمرة واحدة (OTP) بالإضافة إلى كلمة المرور أو المفتاح .
Extra security layer requiring a one-time password (OTP) along with the private key or password .
أوامر SSH في موجه الأوامر (Terminal Commands) SSH: Command Structure & Common Commands §10
هيكل الأمر: ssh [username]@[server_ip_or_hostname]
أمثلة: ssh [email protected] أو ssh [email protected] .
Command Structure: ssh [username]@[server_ip_or_hostname]
Examples: ssh [email protected] or ssh [email protected] .
ssh
Initiate session
scp
Securely copy files
sftp
Secure file transfer
ssh-keygen
Key pair generation
تطبيقات تعتمد على SSH Applications Based on SSH §11
  • الاتصال بجهاز عن بُعد (Connect to a remote device) .
  • الاستخدام مع الشبكات الخاصة الافتراضية (VPN) .
  • النسخ الاحتياطي ونسخ الملفات باستخدام SFTP .
  • ربط منفذ المستخدم بمنفذ الخادم (Port Mapping) لتأمين TCP/IP .
  • إنشاء قنوات (Tunneling) لنقل المعلومات الحساسة عبر قناة محمية .
  • توجيه نظام X Window من الخادم للعملاء .
ملخص المحاضرة — النقاط الرئيسية للمراجعة Chapter Summary – Key Takeaways for Review §12
  • SSH vs Telnet: يعمل Telnet (منفذ 23) كنص واضح غير آمن، بينما SSH (منفذ 22) مشفر وآمن للوصول عن بُعد . Telnet (Port 23) is plaintext, SSH (Port 22) is encrypted and secure .
  • مراحل SSH: يتكون من 5 مراحل: مصافحة TCP، تبادل الهوية، التفاوض على الخوارزميات، تبادل المفاتيح، وطلب الخدمة والمصادقة . 5 stages: TCP Handshake, ID Exchange, Algo Negotiation, Key Exchange, Service Request/Auth .
  • تبادل المفاتيح (Key Exchange): يولد الطرفان سراً مشتركاً، ويوقع الخادم الهاش بمفتاحه الخاص لإثبات هويته. بعد ذلك، يتم توليد 6 مفاتيح جديدة للاتصال . Shared secret is generated, server signs hash with private key. 6 new keys generated for communication .
  • مصادقة العميل (Client Auth): يُفضل استخدام أزواج المفاتيح (Public-Private Key) بدلاً من كلمات المرور للحماية من هجمات Brute-force . Public-Private Key auth is preferred over passwords to prevent brute-force attacks .