์นดํ…Œ๊ณ ๋ฆฌ ์—†์Œ

ํด๋ผ์šฐ๋“œ ์šฐ๋ถ„ํˆฌ ์„œ๋ฒ„์—์„œ SSH ํ‚ค๋กœ root ๊ณ„์ • ๋กœ๊ทธ์ธ ์„ค์ •ํ•˜๊ธฐ | Setting Up SSH Key Authentication for Root Access on a Cloud Ubuntu Server

๊ถŒ๋ผ์—ฐ 2025. 3. 6. 06:24

ํด๋ผ์šฐ๋“œ ํ™˜๊ฒฝ์—์„œ Ubuntu ๊ฐ€์ƒ ๋จธ์‹ ์„ ์ƒ์„ฑํ•˜๋ฉด ๊ธฐ๋ณธ์ ์œผ๋กœ ubuntu ๊ณ„์ •์ด ์ œ๊ณต๋˜๋ฉฐ, SSH ์ ‘์†์„ ์œ„ํ•ด .key ํŒŒ์ผ์ด ์ฃผ์–ด์ง€๋Š” ๊ฒฝ์šฐ๊ฐ€ ๋งŽ๋‹ค. ํ•˜์ง€๋งŒ ๊ธฐ๋ณธ์ ์œผ๋กœ root ๊ณ„์ •์€ ๋น„ํ™œ์„ฑํ™”๋˜์–ด ์žˆ์œผ๋ฉฐ, ๋ณ„๋„์˜ SSH ํ‚ค๊ฐ€ ์„ค์ •๋˜์–ด ์žˆ์ง€ ์•Š๋‹ค. ๋”ฐ๋ผ์„œ ubuntu ๊ณ„์ •์—์„œ ์‚ฌ์šฉํ•˜๋˜ SSH ํ‚ค๋ฅผ root ๊ณ„์ •์—์„œ๋„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ์„ค์ •ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์ •๋ฆฌํ•˜์˜€๋‹ค.

1. root ๊ณ„์ • ํ™œ์„ฑํ™”

Ubuntu์—์„œ๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ root ๊ณ„์ •์ด ๋น„ํ™œ์„ฑํ™”๋˜์–ด ์žˆ๋‹ค. ๋”ฐ๋ผ์„œ root ๊ณ„์ •์œผ๋กœ ์ „ํ™˜ํ•˜๊ธฐ ์œ„ํ•ด ๋‹ค์Œ ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•œ๋‹ค.

sudo -i

๋˜๋Š”

sudo su -

์œ„ ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•˜๋ฉด root ๊ณ„์ •์œผ๋กœ ์ „ํ™˜๋œ๋‹ค.

2. ubuntu ๊ณ„์ •์˜ SSH ํ‚ค ๋ณต์‚ฌ

ubuntu ๊ณ„์ •์—์„œ ์‚ฌ์šฉํ•˜๋˜ SSH ํ‚ค๋ฅผ root ๊ณ„์ •์—์„œ๋„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ๋ณต์‚ฌํ•ด์•ผ ํ•œ๋‹ค. ๋‹ค์Œ ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•˜์—ฌ ubuntu ๊ณ„์ •์˜ authorized_keys ํŒŒ์ผ์„ root ๊ณ„์ •์œผ๋กœ ๋ณต์‚ฌํ•œ๋‹ค.

mkdir -p /root/.ssh
cp /home/ubuntu/.ssh/authorized_keys /root/.ssh/
chown -R root:root /root/.ssh
chmod 700 /root/.ssh
chmod 600 /root/.ssh/authorized_keys

์œ„ ๊ณผ์ •์„ ํ†ตํ•ด root ๊ณ„์ •์—์„œ๋„ ubuntu ๊ณ„์ •๊ณผ ๋™์ผํ•œ SSH ํ‚ค๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.

3. SSH ์„œ๋น„์Šค ์žฌ์‹œ์ž‘ (ํ•„์š”ํ•œ ๊ฒฝ์šฐ)

SSH ์„ค์ •์ด ๋ณ€๊ฒฝ๋˜์—ˆ์œผ๋ฏ€๋กœ, SSH ์„œ๋น„์Šค๋ฅผ ์žฌ์‹œ์ž‘ํ•  ํ•„์š”๊ฐ€ ์žˆ์„ ์ˆ˜ ์žˆ๋‹ค. ๋‹ค์Œ ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•˜์—ฌ SSH ์„œ๋น„์Šค๋ฅผ ์žฌ์‹œ์ž‘ํ•œ๋‹ค.

systemctl restart ssh

4. root ๊ณ„์ •์œผ๋กœ SSH ์ ‘์† ํ…Œ์ŠคํŠธ

์„ค์ •์ด ์™„๋ฃŒ๋˜์—ˆ์œผ๋ฉด, ๋กœ์ปฌ ๋จธ์‹ ์—์„œ ๋‹ค์Œ๊ณผ ๊ฐ™์ด root ๊ณ„์ •์œผ๋กœ SSH ์ ‘์†์ด ๊ฐ€๋Šฅํ•œ์ง€ ํ™•์ธํ•œ๋‹ค.

ssh -i /path/to/private_key root@your-server-ip

๋งŒ์•ฝ Permission denied ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค๋ฉด, SSH ์„ค์ •์—์„œ PermitRootLogin ๊ฐ’์„ ํ™•์ธํ•ด์•ผ ํ•œ๋‹ค. ๋‹ค์Œ ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•˜์—ฌ SSH ์„ค์ • ํŒŒ์ผ์„ ์ˆ˜์ •ํ•œ๋‹ค.

sudo nano /etc/ssh/sshd_config

ํ•ด๋‹น ํŒŒ์ผ์—์„œ PermitRootLogin ๊ฐ’์„ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์„ค์ •ํ•œ๋‹ค.

PermitRootLogin yes

๋˜๋Š”

PermitRootLogin prohibit-password

์„ค์ •์„ ๋ณ€๊ฒฝํ•œ ํ›„ SSH ์„œ๋น„์Šค๋ฅผ ๋‹ค์‹œ ์‹œ์ž‘ํ•œ๋‹ค.

systemctl restart ssh

์ด์ œ root ๊ณ„์ •์—์„œ๋„ ubuntu ๊ณ„์ •์—์„œ ์‚ฌ์šฉํ•˜๋˜ ํ‚ค๋ฅผ ํ™œ์šฉํ•˜์—ฌ SSH ๋กœ๊ทธ์ธํ•  ์ˆ˜ ์žˆ๋‹ค. ์ด๋ฅผ ํ†ตํ•ด ๊ด€๋ฆฌ ํŽธ์˜์„ฑ์„ ๋†’์ด๊ณ , ํ•„์š”ํ•  ๊ฒฝ์šฐ root ๊ณ„์ •์„ ํ™œ์šฉํ•œ ์„œ๋ฒ„ ์„ค์ •์ด ๊ฐ€๋Šฅํ•ด์ง„๋‹ค.