2 ๋ถ„ ์†Œ์š”

๋ณด์•ˆ ์„ค์ •..?

์นœ๊ตฌํ•œํ…Œ ๋‚ด ์„œ๋ฒ„๋ฅผ ๋งŒ๋“ค์—ˆ๋Š”๋ฐ, ์—ฌ๊ธฐ์— ์ง„ํ–‰ ์ค‘์ธ ํ”„๋กœ์ ํŠธ๋ฅผ ๋ฐฐํฌํ•˜๋Š” ๊ฒƒ์€ ์–ด๋–ค์ง€ ์˜๊ฒฌ์„ ์ œ์‹œํ•ด๋ดค๋‹ค.
์นœ๊ตฌ๋Š” ์ž๊ธฐ๋„ ์„œ๋ฒ„๋ฅผ ๊ตฌ์ถ•ํ•ด๋ดค๋Š”๋ฐ, ๊ทธ๊ฒŒ ์—ฐ๊ฒฐ ํ•ด๋†“์€ ์ธํ„ฐ๋„ท์ด ์œ„ํ—˜ํ•  ๊ฒฝ์šฐ๊ฐ€ ์ƒ๊ธธ ์ˆ˜๋„ ์žˆ๋‹ค๊ณ  ํ–ˆ๋‹ค.
๋ณด์•ˆ์ ์ธ ์ธก๋ฉด์—์„œ ์œ„ํ—˜ ์š”์†Œ๊ฐ€ ์žˆ์œผ๋ฉด, ์ธํ„ฐ๋„ท์€ ๋ฌผ๋ก ์ด๊ณ  ๋ฐฐํฌํ•ด๋†“์€ ์„œ๋น„์Šค์˜ ๋ฐ์ดํ„ฐ ๋˜ํ•œ ํ•œ ๋ฒˆ์— ์œ„ํ—˜์— ๋…ธ์ถœ๋˜๊ธฐ ๋•Œ๋ฌธ์— ๋ณด์•ˆ ์„ค์ •์— ๋Œ€ํ•ด์„œ ๊ถ๊ธˆํ•ด์กŒ๋‹ค.
VPN์„ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•๋„ ์žˆ๊ณ , ๋‹จ์ˆœํ•˜๊ฒŒ ์ธํ„ฐ๋„ท์„ ๋”ฐ๋กœ ๊ฐœํ†ตํ•ด์„œ ๊ทธ๊ฑธ ์“ฐ๋Š” ๋ฐฉ๋ฒ•๋„ ์žˆ๊ณ .. ๋‹ค์–‘ํ•œ ๋ฐฉ๋ฒ•๋“ค์ด ์žˆ๋‹ค.
๋‚˜๋Š” ์šฐ์„  ๋‚ด ์„œ๋ฒ„์— ์ ‘์†ํ•˜๋Š” ํด๋ผ์ด์–ธํŠธ์— ๋Œ€ํ•œ ๋ณด์•ˆ ์„ค์ •์„ ํ•˜๋Š”๊ฒŒ ์–ด๋–จ๊นŒ ํ•˜๋Š” ์ƒ๊ฐ์— ChatGPT์—๊ฒŒ ๋ฌผ์–ด๋ดค๋‹ค.

์ดํ›„์— ๊ตฌ๊ธ€๋ง๊ณผ ์—ฌ๋Ÿฌ ๋ธ”๋กœ๊ทธ ํฌ์ŠคํŒ…๋„ ์ฐธ๊ณ ํ•˜๋ฉด์„œ ๋ณด์•ˆ์„ฑ์ด ํ–ฅ์ƒ๋œ ์„œ๋ฒ„๋ฅผ ๊ตฌ์ถ•ํ•ด๋ณผ๊ฑฐ์ž„!

1. SSH ๊ธฐ๋ณธ ์„ค์ • ๋ณ€๊ฒฝ

SSH ํฌํŠธ ๋ณ€๊ฒฝ

๊ธฐ๋ณธ์ ์œผ๋กœ SSH๋Š” 22๋ฒˆ ํฌํŠธ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.

์ด๋ฅผ ๋ณ€๊ฒฝํ•˜์—ฌ ์ž๋™ ์Šค์บ” ๊ณต๊ฒฉ ์„ ๋ฐฉ์ง€ํ•  ์ˆ˜ ์žˆ๋‹ค.

sudo nano /etc/ssh/sshd_config
  • sshd_config ์— ์ ‘์†
Port 2222
  • ํฌํŠธ ๋ณ€๊ฒฝ
sudo systemctl restart ssh 
  • SSH ๋ฐ๋ชฌ ์žฌ์‹œ์ž‘

๋ฃจํŠธ ๋กœ๊ทธ์ธ ๋น„ํ™œ์„ฑํ™”

๋ฃจํŠธ ๊ณ„์ •์œผ๋กœ ์ง์ ‘ ์ ‘์†ํ•˜๋Š” ๊ฒƒ์„ ๋น„ํ™œ์„ฑํ™”ํ•œ๋‹ค.

sudo nano /etc/ssh/sshd_config
  • sshd_config ์— ์ ‘์†
PermitRootLogin no
  • PermitRootLogin ์„ค์ • no ๋กœ ๋ณ€๊ฒฝ
sudo systemctl restart ssh
  • ์•”ํ˜ธ ์ธ์ฆ ๋น„ํ™œ์„ฑํ™” ๋ฐ ๊ณต๊ฐœ ํ‚ค ์ธ์ฆ ์‚ฌ์šฉ
  • ์•”ํ˜ธ ์ธ์ฆ์„ ๋น„ํ™œ์„ฑํ™”ํ•˜๊ณ , ๊ณต๊ฐœ ํ‚ค ์ธ์ฆ์„ ์‚ฌ์šฉํ•˜๋„๋ก ์„ค์ •ํ•œ๋‹ค.
sudo nano /etc/ssh/sshd_config
  • sshd_config ์— ์ ‘์†
PasswordAuthentication no
  • PasswordAuthentication ์„ค์ • no๋กœ ๋ณ€๊ฒฝ
sudo systemctl restart ssh
  • SSH ๋ฐ๋ชฌ ์žฌ์‹œ์ž‘
# ํด๋ผ์ด์–ธํŠธ ์ปดํ“จํ„ฐ
ssh-keygen -t rsa
# ssh-copy-id username@server_ip
ssh-copy-id -i /path/to/your_rsa_key.pub user@server_ip -p [PORT]
  • ๊ณต๊ฐœ ํ‚ค ์ธ์ฆ์„ ์„ค์ •ํ•˜๋ ค๋ฉด, ํด๋ผ์ด์–ธํŠธ ์ปดํ“จํ„ฐ์—์„œ ๊ณต๊ฐœ ํ‚ค๋ฅผ ์ƒ์„ฑํ•˜๊ณ , ์„œ๋ฒ„์— ์—…๋กœ๋“œ ํ•ด์•ผํ•œ๋‹ค.
  • ssh-copy-id username@server_ip ๋ฅผ ํ–ˆ๋Š”๋ฐ, ์„œ๋ฒ„์— ์ „์†ก์ด ์•ˆ๋œ ๋“ฏํ•˜๋‹ค..
  • ๊ทธ๋ž˜์„œ ssh-copy-id -i /path/to/your_rsa_key.pub user@server_ip -p [PORT]๋ฅผ ์‚ฌ์šฉํ•ด์„œ .pubํ‚ค๋ฅผ ๋ณด๋‚ด์คฌ๋‹ค.
# ์„œ๋ฒ„ ์ปดํ“จํ„ฐ
cd .ssh/
cat authorized_keys
  • ์„œ๋ฒ„ ์ธก ์ปดํ“จํ„ฐ์—์„œ ํ‚ค๊ฐ€ ์ •์ƒ์ ์œผ๋กœ ๋„˜์–ด์™”๋Š”์ง€ ํ™•์ธํ•ด๋ณด์ž!
  • ์ค„ ์ˆ˜๊ฐ€ ๋Š˜์–ด๋‚ฌ์œผ๋ฉด ๋„˜์–ด์˜จ๊ฑฐ์ž„.
# ๋‹ค์‹œ ํด๋ผ์ด์–ธํŠธ ์ปดํ“จํ„ฐ
Host server_alias
    HostName server_ip
    Port 2222
    User user
    IdentityFile /path/to/your_rsa_key
  • ์ด๋ ‡๊ฒŒ ์„ค์ •ํ•ด๋†“์œผ๋ฉด ๋‚ด ์„œ๋ฒ„์— ์ ‘์†ํ•  ๋•Œ ssh server_alias ๋ช…๋ น์–ด ์ž…๋ ฅํ•˜๋ฉด ๋“ค์–ด๊ฐ€์ง„๋‹ค!
  • ๋‚˜๋Š” server_alias๋ฅผ my_ubuntu๋กœ ํ–ˆ๋‹ค!
ssh my_ubuntu
  • ๊ทธ๋Ÿผ ์ ‘์†ํ•  ๋•Œ, ์•„๊นŒ ์„ค์ •ํ•œ rsaํ‚ค๋ฅผ ๋งŒ๋“ค ๋•Œ ์„ค์ •ํ•œ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด์•ผ ์ ‘์†ํ•  ์ˆ˜ ์žˆ๋‹ค!

2. ๋ฐฉํ™”๋ฒฝ ์„ค์ •

์šฐ๋ถ„ํˆฌ์˜ ๊ธฐ๋ณธ ๋ฐฉํ™”๋ฒฝ์ธ UFW๋ฅผ ์„ค์ •ํ•˜์—ฌ ํ•„์š”ํ•œ ํฌํŠธ๋งŒ ์—ด์–ด์ค€๋‹ค.

sudo ufw allow 2222/tcp
sudo ufw enable
sudo ufw status

3. Fail2Ban ์ ์šฉ

sudo apt update
sudo apt install fail2ban
  • Fail2Ban์€ SSH ๋กœ๊ทธ์ธ ์‹œ๋„๋ฅผ ๋ชจ๋‹ˆํ„ฐ๋งํ•˜๊ณ , ์—ฌ๋Ÿฌ ๋ฒˆ ์‹คํŒจํ•œ IP๋ฅผ ์ฐจ๋‹จํ•œ๋‹ค.
sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
  • ๊ธฐ๋ณธ ์„ค์ • ํŒŒ์ผ์„ ๋ณต์‚ฌํ•˜์—ฌ ์‚ฌ์šฉ์ž ์„ค์ • ํŒŒ์ผ์„ ๋งŒ๋“ค์–ด์ค€๋‹ค.
sudo nano /etc/fail2ban/jail.local
  • ์‚ฌ์šฉ์ž ์„ค์ • ํŒŒ์ผ์„ ํŽธ์ง‘ํ•œ๋‹ค.
[sshd]
enabled = true
port = 2222
filter = sshd
logpath = /var/log/auth.log
maxretry = 5
  • ์‚ฌ์šฉ์ž ์„ค์ • ํŒŒ์ผ์—์„œ [sshd] ์„น์…˜์„ ์ฐพ์•„ ์œ„์™€ ๊ฐ™์ด ๋ณ€๊ฒฝํ•ด์ค€๋‹ค.
sudo systemctl restart fail2ban
  • Fail2Ban์„ ์žฌ์‹œ์ž‘ํ•œ๋‹ค.

2๋‹จ๊ณ„ ์ธ์ฆ ์„ค์ •(Google Authenticator)

2๋‹จ๊ณ„ ์ธ์ฆ์„ ์‚ฌ์šฉํ•˜๋ฉด ๋ณด์•ˆ์„ ๋”์šฑ ๊ฐ•ํ™”ํ•  ์ˆ˜ ์žˆ๋‹ค.

์—ฌ๊ธฐ์„  Google Authenticator๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.

sudo apt install libpam-google-authenticator
  • libpam-google-authenticator๋ฅผ ์„ค์น˜ํ•œ๋‹ค.
google-authenticator
  • ๊ฐ ์‚ฌ์šฉ์ž ๊ณ„์ •์—์„œ Google Authenticator๋ฅผ ์„ค์ •ํ•œ๋‹ค.
sudo nano /etc/pam.d/sshd
  • /etc/pam.d/sshdํŒŒ์ผ์„ ์—ฐ๋‹ค.
auth required pam_google_authenticator.so
  • ์œ„์˜ ์ค„์„ ์ถ”๊ฐ€ํ•˜์—ฌ PAM ๋ชจ๋“ˆ์„ ์ถ”๊ฐ€ํ•œ๋‹ค.
sudo nano /etc/ssh/sshd_config
  • sshd_config ํŒŒ์ผ์„ ์—ฐ๋‹ค.
ChallengeResponseAuthentication yes
  • ChallengeResponseAuthentication ์˜ต์…˜์„ yes๋กœ ๋ฐ”๊ฟ”์ค€๋‹ค.
sudo systemctl restart ssh
  • SSH ๋ฐ๋ชฌ์„ ์žฌ์‹œ์ž‘ํ•œ๋‹ค.

์ฐธ๊ณ ์ž๋ฃŒ

๋‚ด ์šฐ๋ถ„ํˆฌ ์„œ๋ฒ„์— ์•„๋ฌด๋‚˜ ์ ‘์†ํ•  ์ˆ˜ ์—†๋„๋ก ๋ณด์•ˆ์„ค์ • ํ•˜๋Š” ๋ฐฉ๋ฒ• ์•Œ๋ ค์ค˜

ํƒœ๊ทธ: ,

์นดํ…Œ๊ณ ๋ฆฌ:

์—…๋ฐ์ดํŠธ:

๋Œ“๊ธ€๋‚จ๊ธฐ๊ธฐ