๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๊ฐœ๋ฐœ/Linux

[Linux] ํŒจ์Šค์›Œ๋“œ ์—†์ด ์„œ๋ฒ„ ๊ฐ„ ํŒŒ์ผ ์ „์†กํ•˜๊ธฐ : ssh-keygen

by ynzu๐Ÿค 2022. 5. 18.
๋ฐ˜์‘ํ˜•

 

๋ฆฌ๋ˆ…์Šค์—์„œ ๋‹ค๋ฅธ ์„œ๋ฒ„๋กœ ํŒŒ์ผ์„ ๋ณต์‚ฌํ•˜๊ธฐ ์œ„ํ•ด์„œ scp ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•œ๋‹ค.

์˜ˆ์‹œ
$scp "ํŒŒ์ผ๋ช…" "๋‹ค๋ฅธ ์„œ๋ฒ„ ๊ณ„์ •"@"๋‹ค๋ฅธ ์„œ๋ฒ„ ip":"path"


ํ•˜์ง€๋งŒ ์ด ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ์ƒ๋Œ€ ์„œ๋ฒ„์˜ ํŒจ์Šค์›Œ๋“œ๋ฅผ ํ•„์ˆ˜๋กœ ์ž…๋ ฅํ•ด์•ผ ํ•œ๋‹ค.
๋ณธ์ธ์€ ์„œ๋ฒ„๊ฐ„ ํŒŒ์ผ ์ „์†ก์„ ์‰˜์Šคํฌ๋ฆฝํŠธ ํŒŒ์ผ๋กœ ๋งŒ๋“ค์–ด ์‚ฌ๋žŒ์˜ ๊ฐœ์ž…์—†์ด ์ฃผ๊ธฐ์ ์œผ๋กœ ํ•ด์•ผํ–ˆ๊ณ .. ๋•Œ๋ฌธ์— ํŒจ์Šค์›Œ๋“œ ์—†์ด ์ „์†กํ•˜๋Š” ๊ฒƒ์ด ํ•„์š”ํ–ˆ๋‹ค!

 

ssh-keygen์„ ์ด์šฉํ•˜์—ฌ ๋‚ด ์„œ๋ฒ„์—์„œ ๊ณต๊ฐœํ‚ค๋ฅผ ์ƒ์„ฑํ•˜๊ณ , ์ด๋ฅผ ์ƒ๋Œ€ ์„œ๋ฒ„์— ๋ณด๋‚ด๋†“์œผ๋ฉด ํŒจ์Šค์›Œ๋“œ์—†์ด ํŒŒ์ผ ์ „์†ก์ด ๊ฐ€๋Šฅํ•˜๋‹ค.

 

1. ๋‚ด ์„œ๋ฒ„์—์„œ RSA ๊ณต๊ฐœํ‚ค ์ƒ์„ฑ

ssh-keygen -t rsa

์„ธ๋ฒˆ ์ž…๋ ฅํ•˜๋Š” ๋ถ€๋ถ„์ด ๋‚˜์˜ค๋Š”๋ฐ ๊ทธ๋ƒฅ ์—”ํ„ฐ์ณ๋„ ๋ฌด๋ฐฉํ•˜๋‹ค!

 

/home/๊ณ„์ •์— .ssh ๋””๋ ‰ํ† ๋ฆฌ๊ฐ€ ์ƒ๊ฒผ๊ณ , .ssh ๋””๋ ‰ํ† ๋ฆฌ์— id_rsa, id_rsa.pub ํŒŒ์ผ์ด ์ƒ์„ฑ๋๋‹ค.

 

2. id_rsa.pub ํŒŒ์ผ์„ ์ƒ๋Œ€ ์„œ๋ฒ„๋กœ ์ „์†ก

์ƒ๋Œ€์„œ๋ฒ„์˜ /home/๊ณ„์ •/.ssh ๋””๋ ‰ํ† ๋ฆฌ๋กœ id_rsa.pub ํŒŒ์ผ์„ ์ „์†กํ•ด์•ผํ•œ๋‹ค.

์ƒ๋Œ€์„œ๋ฒ„์— .ssh ๋””๋ ‰ํ† ๋ฆฌ๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š๋Š”๋‹ค๋ฉด ์ง์ ‘ ์ƒ์„ฑํ•˜๋ฉด ๋˜๊ณ , ์—ฌ๊ธฐ์„œ ์ฃผ์˜ํ•ด์•ผํ•  ์ ์€ id_rsa.pub ํŒŒ์ผ์„ authorized_keys๋กœ ๋ณ€๊ฒฝํ•˜์—ฌ ๋ณด๋‚ด์•ผํ•œ๋‹ค.

scp /home/๊ณ„์ •๋ช…/.ssh/id_rsa.pub ์ƒ๋Œ€_์„œ๋ฒ„_๊ณ„์ •๋ช…@์ƒ๋Œ€_์„œ๋ฒ„_IP:/home/์ƒ๋Œ€_์„œ๋ฒ„_๊ณ„์ •๋ช…/.ssh/authorized_keys

 

์—ฌ๊ธฐ๊นŒ์ง€ ํ•˜๊ณ  scp๋ฅผ ๋ช…๋ น์–ด๋ฅผ ์ด์šฉํ•˜์—ฌ ์ƒ๋Œ€์„œ๋ฒ„๋กœ ํŒŒ์ผ์„ ์ „์†กํ•œ๋‹ค๋ฉด ํŒจ์Šค์›Œ๋“œ ์—†์ด ์ „์†ก์ด ๊ฐ€๋Šฅํ•˜๋‹ค.

 

728x90
๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€