Skip to content
GitHub

SSH Key Cryptography နှင့် VPS Server Access Hardening

SSH Key Cryptography အလုပ်လုပ်ပုံ (Public vs Private Key)

Section titled “SSH Key Cryptography အလုပ်လုပ်ပုံ (Public vs Private Key)”

SSH Keys စနစ်သည် Asymmetric Cryptography (မညီမျှသော သော့တွဲစနစ်) ပေါ်တွင် အခြေခံထားပါတယ်:

graph LR
subgraph Developer Laptop
PrivKey["🔑 Private Key (id_ed25519)<br/>မိမိစက်ထဲတွင်သာ အလုံပိတ် သိမ်းဆည်းရမည်"]
end
subgraph Cloud VPS Server
PubKey["🔓 Public Key (id_ed25519.pub)<br/>~/.ssh/authorized_keys ထဲသို့ ထည့်သွင်းထားသည်"]
end
PrivKey -.->|Cryptographic Handshake| PubKey
  1. Private Key (id_ed25519): ခင်ဗျား၏ Laptop ထဲတွင်သာ အမြဲရှိနေရမည်ဖြစ်ပြီး မည်သူ့ကိုမျှ (GitHub အပါအဝင်) လုံးဝ မပြသရသော လျှို့ဝှက်သော့ ဖြစ်သည်။
  2. Public Key (id_ed25519.pub): Server ပေါ်သို့ ပို့ဆောင်သိမ်းဆည်းထားသော အများပြည်သူသုံး သော့ခလောက် ဖြစ်သည်။

အဆင့် ၁: Local Computer တွင် SSH Key Pair ထုတ်ယူခြင်း

Section titled “အဆင့် ၁: Local Computer တွင် SSH Key Pair ထုတ်ယူခြင်း”

မိမိ၏ Mac သို့မဟုတ် Windows Terminal တွင် အောက်ပါ Command ကို Run ပါ (RSA ထက် ပိုမိုမြန်ဆန်ပြီး လုံခြုံသော Ed25519 ကို အသုံးပြုပါသည်):

Terminal window
ssh-keygen -t ed25519 -C "admin@takkatho.dev"
  1. ဖိုင်သိမ်းမည့် နေရာ မေးပါက Enter သာ နှိပ်ပါ။ (Default: ~/.ssh/id_ed25519)
  2. Passphrase (စကားဝှက်) မေးပါက အပိုလုံခြုံရေးအတွက် စကားဝှက် ရိုက်ထည့်နိုင်ပါသည် သို့မဟုတ် Enter နှိပ်၍ ကျော်နိုင်ပါသည်။

အဆင့် ၂: Public Key အား Server ပေါ်သို့ ကူးယူတင်သွင်းခြင်း

Section titled “အဆင့် ၂: Public Key အား Server ပေါ်သို့ ကူးယူတင်သွင်းခြင်း”
Section titled “နည်းလမ်း A: ssh-copy-id ဖြင့် အလွယ်တကူ တင်ခြင်း (Recommended)”
Terminal window
ssh-copy-id ubuntu@YOUR_VPS_IP

နည်းလမ်း B: Manual ကူးယူနည်း

Section titled “နည်းလမ်း B: Manual ကူးယူနည်း”

အကယ်၍ ssh-copy-id မရပါက မိမိစက်မှ Public Key ကို ကူးယူပါ:

Terminal window
cat ~/.ssh/id_ed25519.pub

ထွက်လာသော ssh-ed25519 AAAA... စာကြောင်းရှည်ကို Copy ကူးပြီး Server ထဲရှိ ~/.ssh/authorized_keys ထဲသို့ သွားရောက် Paste လုပ်ပေးရပါမည်:

Terminal window
# Server ပေါ်တွင်:
mkdir -p ~/.ssh
chmod 700 ~/.ssh
nano ~/.ssh/authorized_keys
# (Paste the public key here)
chmod 600 ~/.ssh/authorized_keys

အဆင့် ၃: SSH Server Configuration ကို Hardening ပြုလုပ်ခြင်း

Section titled “အဆင့် ၃: SSH Server Configuration ကို Hardening ပြုလုပ်ခြင်း”

ယခုအခါ Password မလိုဘဲ SSH Key ဖြင့်သာ Login ဝင်ခွင့်ပြုရန် Server ၏ SSH Config ကို ပြင်ဆင်ပါမည်:

Terminal window
sudo nano /etc/ssh/sshd_config

အောက်ပါ Setting ၃ ခုကို ရှာဖွေ၍ ပြင်ဆင်ပါ:

# 1. Root အကောင့်ဖြင့် တိုက်ရိုက် SSH ဝင်ခွင့်ကို ပိတ်မည်
PermitRootLogin no
# 2. စကားဝှက် (Password) ဖြင့် Login ဝင်ခွင့်ကို လုံးဝ ပိတ်မည် (Brute-force ကာကွယ်ရန်)
PasswordAuthentication no
# 3. Public Key ဖြင့်သာ Login ဝင်ခွင့်ကို ဖွင့်မည်
PubkeyAuthentication yes

အဆင့် ၄: SSH Service ကို Restart မလုပ်မီ စစ်ဆေးခြင်း

Section titled “အဆင့် ၄: SSH Service ကို Restart မလုပ်မီ စစ်ဆေးခြင်း”
Terminal window
# SSH Daemon ကို Restart လုပ်မည်
sudo systemctl restart ssh
# (သို့မဟုတ် Ubuntu အချို့တွင်)
sudo systemctl restart sshd

Local Computer ရှိ Terminal Tab အသစ်မှ စမ်းသပ် Login ဝင်ခြင်း:

Section titled “Local Computer ရှိ Terminal Tab အသစ်မှ စမ်းသပ် Login ဝင်ခြင်း:”
Terminal window
ssh -i ~/.ssh/id_ed25519 ubuntu@YOUR_VPS_IP

Password တောင်းဆိုခြင်း မရှိဘဲ ချက်ချင်း Server ထဲသို့ ရောက်ရှိသွားပါက ခင်ဗျား၏ VPS သည် အောင်မြင်စွာ လုံခြုံသွားပြီ ဖြစ်ပါသည်။


🎯 သင်ခန်းစာ အနှစ်ချုပ်

Section titled “🎯 သင်ခန်းစာ အနှစ်ချုပ်”
  • အမြဲတမ်း ed25519 SSH Key algorithm ကို သုံးပါ။
  • Server ပေါ်တွင် PasswordAuthentication no သတ်မှတ်ပါ။
  • Root User ဖြင့် တိုက်ရိုက် Login မဝင်ဘဲ sudo User ဖြင့်သာ ဝင်ရောက်ပါ။
📖

ဒီသင်ခန်းစာ ဖတ်ပြီးပြီလား?

ပြီးမြောက်ကြောင်း မှတ်သားထားရန် အောက်ပါ ခလုတ်ကို နှိပ်ပါ