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

OS/๐Ÿง Linux

๐Ÿง Ubuntu * scp, ssh ๋น„๋ฐ€๋ฒˆํ˜ธ/์•”ํ˜ธ ์—†์ด ์‚ฌ์šฉ/๋กœ๊ทธ์ธํ•˜๊ธฐ

ssh ๋‚˜ scp ์‚ฌ์šฉ์‹œ ๋งค๋ฒˆ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•˜๋Š” ๊ฒƒ์€ ๋งค์šฐ ๊ท€์ฐฎ๋‹ค.

์ด๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ์•„๋ž˜์™€ ๊ฐ™์€ ๋ฐฉ๋ฒ• ๋“ค์ด ์žˆ๋‹ค.

 

  1. ๊ณต๊ฐœํ‚ค๋ฅผ ์›๊ฒฉ ์„œ๋ฒ„์— ๋ฏธ๋ฆฌ ๋“ฑ๋ก์‹œํ‚จ๋‹ค.
  2. sshpass ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.
  3. expect ๋ช…๋ น์–ด๋ฅผ ์ด์šฉํ•ด ๋น„๋ฐ€๋ฒˆํ˜ธ ์ž…๋ ฅ์„ ์ž๋™ํ™” ํ•œ๋‹ค.

 

์ด ์ค‘์—์„œ๋„ 1๋ฒˆ ๋ฐฉ๋ฒ•์€ ๋ณด์•ˆ์ƒ์œผ๋กœ๋„ ๊ฐ€์žฅ ์•ˆ์ „ํ•˜๋ฉฐ ๋“ฑ๋กํ•˜๋Š” ๋ฐฉ๋ฒ•๋„ ๋ณต์žกํ•˜์ง€์•Š๋‹ค.

 

2๋ฒˆ ๋ฐฉ๋ฒ•์€ ssh์™€ ์ง์ ‘๊ด€๊ณ„๊ฐ€ ์—†๋Š” ํ”„๋กœ๊ทธ๋žจ์ž„์œผ๋กœ ๋ณ„๋„์˜ ์„ค์น˜๊ฐ€ ํ•„์š”ํ•˜๋ฉฐ, ๋น„๋ฒˆ์ž๋™ ์ž…๋ ฅ์™ธ์—๋„ ๋‹ค์–‘ํ•œ ๊ธฐ๋Šฅ์„ ์ œ๊ณต ํ•œ๋‹ค๊ณ ๋Š” ํ•˜๋‚˜ ์“ฐ๋‹ˆ๋Š” ํ•„์š”์—†๋‹ค๊ณ  ํŒ๋‹จ๋˜์—ˆ๊ธฐ์— ์ด๋Ÿฐ ๋ฐฉ๋ฒ•์ด ์žˆ๋‹ค๋Š” ๊ฒƒ๋งŒ ์•Œ๋ฆฐ๋‹ค.

 

3๋ฒˆ ๋ฐฉ๋ฒ•์€ sshpass๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๋Š” ์ƒํ™ฉ์—์„œ ์“ฐ๋ฉด ์ข‹๋‹ค๊ณ  ํ•˜๋Š”๋ฐ ssh ์ž๋™ ๋กœ๊ทธ์ธ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ๋„˜๊ธด๋‹ค๊ณ  ํ•œ๋‹ค.

 

์—ฌ๊ธฐ์„œ๋Š” 1๋ฒˆ ๋ฐฉ๋ฒ•์„ ์‚ฌ์šฉํ•˜์—ฌ ๋น„๋ฐ€๋ฒˆํ˜ธ ์—†์ด scp, ssh๋ฅผ ์‚ฌ์šฉํ•˜๋„๋ก ํ•˜๊ฒ ๋‹ค!

2๋ฒˆ ๋ฐฉ๋ฒ•์ด ๊ถ๊ธˆํ•˜๋‹ค๋ฉด Thanks for์— 1๋ฒˆ ํŽ˜์ด์ง€๋ฅผ

3๋ฒˆ ๋ฐฉ๋ฒ•์ด ๊ถ๊ธˆํ•˜๋‹ค๋ฉด Thanks for์— 2๋ฒˆ ํŽ˜์ด์ง€๋ฅผ ๋ฐฉ๋ฌธํ•˜๋„๋ก ํ•˜์ž!

 

 


 

๊ณต๊ฐœํ‚ค๋ฅผ ๋„˜๊ฒจ์ฃผ๊ธฐ ์ „์— ๋‹น์—ฐํžˆ ๊ณต๊ฐœํ‚ค๋ฅผ ์ƒ์„ฑํ–ˆ์–ด์•ผ ํ•œ๋‹ค!

์ƒ์„ฑ์„ ํ–ˆ๋Š”์ง€ ์•ˆํ–ˆ๋Š”์ง€ ๋ชจ๋ฅด๊ฒ ๋‹ค? ์ƒ์„ฑ์„ ์•ˆ ํ–ˆ๋‹ค?

๐Ÿ‘‰ 2020/03/05 - [OS/๐Ÿง Linux] - ๐Ÿง Ubuntu * ๊ณต๊ฐœํ‚ค ์ƒ์„ฑํ•˜๊ธฐ

 

๊ณต๊ฐœํ‚ค๋ฅผ ๋„˜๊ฒจ์ฃผ์ž

 

์ด์ œ ๊ณต๊ฐœํ‚ค๋ฅผ ์›๊ฒฉ ์„œ๋ฒ„์— ๋“ฑ๋กํ•ด์•ผ ํ•˜๋Š”๋ฐ, scp ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์ด ์žˆ๊ณ  ssh-copy-id๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์ด ์žˆ๋‹ค.

 

scp ๋ฐฉ๋ฒ•์„ ์‚ฌ์šฉํ•˜๋ฉด ๊ธฐ์กด ํŒŒ์ผ์ด ์กด์žฌํ•  ๊ฒฝ์šฐ ๋ฎ์–ด์“ฐ๊ฒŒ ๋จ์œผ๋กœ ๊ถŒ์žฅํ•˜์ง€ ์•Š๋Š”๋‹ค๊ณ  ํ•œ๋‹ค.

ํ•˜์—ฌ ssh-copy-id๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•๋งŒ ์•Œ๋ ค๋“œ๋ฆฌ๋ คํ•œ๋‹ค.

 

tip. ์ด๊ฑด ํ˜น์‹œ๋‚˜ ํ•ด์„œ.. window์—์„œ๋Š” ssh-copy-id ๋ช…๋ น์–ด๊ฐ€ ์—†๋‹ค๊ณ  ํ•œ๋‹ค.

ํ•ด์„œ scp๋กœ ์›๊ฒฉ์ง€(Ubuntu)์— ๋กœ๊ทธ์ธ ํ•œ ํ›„ ์ˆ˜๋™์œผ๋กœ ๊ณต๊ฐœํ‚ค๋ฅผ ๋ณต์‚ฌํ•ด์•ผ ํ•œ๋‹ค.

 

ssh-copy-id ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด, ์›๊ฒฉ ์„œ๋ฒ„์— authorized_keys ํŒŒ์ผ์ด ์—†๋‹ค๋ฉด ์ƒ์„ฑํ•ด์ฃผ๊ณ  ๊ณต๊ฐœํ‚ค๋ฅผ ์ถ”๊ฐ€ํ•ด์ค€๋‹ค๊ณ  ํ•œ๋‹ค.

 

$ ssh-copy-id -i ~/.ssh/id_rsa.pub ์œ ์ €์ด๋ฆ„@ํ˜ธ์ŠคํŠธ์ฃผ์†Œ

 

๋งŒ์•ฝ ๊ธฐ์กด 22๋ฒˆ ํฌํŠธ ์™ธ์— ๋‹ค๋ฅธ ํฌํŠธ ๋ฒˆํ˜ธ๋กœ ssh ์ ‘์†์„ ์‹œ๋„ํ•œ๋‹ค๋ฉด -p ์˜ต์…˜์„ ํ†ตํ•ด์„œ ํฌํŠธ๋ฅผ ์ง€์ •ํ•ด ์ฃผ์–ด์•ผ ํ•œ๋‹ค.

ex )  $ ssh-copy-id -p ํฌํŠธ๋ฒˆํ˜ธ -i ~/.ssh/id_rsa.pub ์œ ์ €์ด๋ฆ„@ํ˜ธ์ŠคํŠธ์ฃผ์†Œ

 

์—ฌ๊ธฐ๊นŒ์ง€ ์™„๋ฃŒํ–ˆ๋‹ค๋ฉด ์ด์ œ ๋น„๋ฐ€๋ฒˆํ˜ธ ์—†์ด scp, ssh ์‚ฌ์šฉ์ด ๊ฐ€๋Šฅํ•˜๋‹ค!

 

๊ฐ„ํ˜น ์›๊ฒฉ ์„œ๋ฒ„์˜ authorized_keys ํŒŒ์ผ ๊ถŒํ•œ ๋•Œ๋ฌธ์— ์•ˆ๋˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ์ข…์ข… ๋ฐœ์ƒํ•œ๋‹ค๊ณ  ํ•œ๋‹ค.

์›๊ฒฉ ์„œ๋ฒ„์—์„œ ๊ถŒํ•œ์„ ์•„๋ž˜์™€ ๊ฐ™์ด ์„ค์ •ํ•ด ์ฃผ๋ฉด ๋Œ€๋ถ€๋ถ„์˜ ๊ฒฝ์šฐ ์ ‘์† ๋ฌธ์ œ๊ฐ€ ํ•ด๊ฒฐ๋œ๋‹ค๊ณ  ํ•œ๋‹ค.

 

$ chmod 700 ~/.ssh/
$ chmod 600 ~/.ssh/authorized_keys

 

๊ทธ ์ค‘์—์„œ๋„ ๋งŒ์•ฝ selinux๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ๋Š” ์ถ”๊ฐ€์ ์œผ๋กœ ํ•ด์ค˜์•ผ ํ•  ๋ถ€๋ถ„์ด ์žˆ๋‹ค.

์—ฌ๊ธฐ์„œ๋Š” ์„ค๋ช…ํ•˜์ง€ ์•Š์œผ๋‹ˆ Thanks for์˜ 1๋ฒˆ์„ ์ฐธ๊ณ ํ•˜์ž.

 

 


Thanks for

  1. SSH ๋น„๋ฐ€๋ฒˆํ˜ธ ์ž…๋ ฅ์—†์ด ๋กœ๊ทธ์ธํ•˜๊ธฐ
  2. scp, ssh, rsyn๋ฅผ ๋น„๋ฐ€ ๋ฒˆํ˜ธ/์•”ํ˜ธ ์ž…๋ ฅ์ฐฝ ์—†์ด ์‚ฌ์šฉํ•˜๊ธฐ
  3. SSH Key - ๋น„๋ฐ€๋ฒˆํ˜ธ ์—†์ด ๋กœ๊ทธ์ธ