Bibi's DevLog ๐Ÿค“๐ŸŽ

[AWS] public ์ธ์Šคํ„ด์Šค๋ฅผ ํ†ตํ•ด private์ธ์Šคํ„ด์Šค ์ ‘์†ํ•˜๊ธฐ (key forwarding ํ‚ค ํฌ์›Œ๋”ฉ, ssh agent) ๋ณธ๋ฌธ

๐Ÿ–ฅ BE ๋ฐฑ์—”๋“œ/AWS

[AWS] public ์ธ์Šคํ„ด์Šค๋ฅผ ํ†ตํ•ด private์ธ์Šคํ„ด์Šค ์ ‘์†ํ•˜๊ธฐ (key forwarding ํ‚ค ํฌ์›Œ๋”ฉ, ssh agent)

๋น„๋น„ bibi 2021. 6. 4. 00:22

public์„ ํ†ตํ•ด private ์ ‘์†ํ•˜๊ธฐ

https://velog.io/@yeon/public-subnet%EA%B3%BC-private-subnet%EC%97%90-%EC%9B%B9%EC%84%9C%EB%B2%84%EC%99%80-%EB%8D%B0%EC%9D%B4%ED%84%B0%EB%B2%A0%EC%9D%B4%EC%8A%A4-%EB%B6%84%EB%A6%AC%ED%95%B4%EC%84%9C-%EB%B0%B0%ED%8F%AC%ED%95%98%EA%B8%B0 ์—ฐ ๋ธ”๋กœ๊ทธ์—์„œ ์ „์ฒด์ ์ธ ๊ณผ์ • ์ฐธ๊ณ ํ•˜๊ธฐ

https://rutesun.wordpress.com/2015/02/04/git-bash-%EA%B0%9C%EC%9D%B8%ED%82%A4-%EB%93%B1%EB%A1%9D%EC%8B%9C-%EC%97%90%EB%9F%AC/ ์—์„œ ssh agent ์ดˆ๊ธฐ ์…‹ํŒ… ์ฐธ๊ณ ํ•˜๊ธฐ

private์ธ์Šคํ„ด์Šค(DB ์ธ์Šคํ„ด์Šค)์— ์ ‘์†ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” public์ธ์Šคํ„ด์Šค(์„œ๋ฒ„ ์ธ์Šคํ„ด์Šค)์—์„œ ์ ‘์†ํ•  ๋•Œ private์ธ์Šคํ„ด์Šค์˜ ํ‚คํŒŒ์ผ(.pem)์„ ํ•จ๊ป˜ ๊ฐ€์ง€๊ณ  ์ ‘์†ํ•ด์•ผ ํ•œ๋‹ค.
์ด ๋•Œ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ssh agent์ด๋‹ค.
ssh์ ‘์† ์‹œ agent๋ฅผ ๋ถ™์—ฌ์„œ, ๊ทธ agent๊ฐ€ ํ‚คํŒŒ์ผ์„ ๊ฐ€์ง€๊ณ  ํ•จ๊ป˜ ์ ‘์†ํ•˜๋„๋ก ํ•œ๋‹ค.

private, public ํ‚คํŒŒ์ผ(.pem)์ด ์กด์žฌํ•˜๋Š” ๊ฒฝ๋กœ์—์„œ ์•„๋ž˜ ์ปค๋งจ๋“œ๋ฅผ ์‹คํ–‰ํ•ด์•ผ ํ•œ๋‹ค

ssh-agent -s : ssh-agent๋ฅผ ์‹œ์ž‘ํ•œ๋‹ค

ssh-add ~/ํ‚คํŒŒ์ผ๊ฒฝ๋กœ : ssh-agent์— ํ‚ค๋ฅผ ๋“ฑ๋กํ•œ๋‹ค.

eval $(ssh-agent) : ssh-agent๋ฅผ ์‹œ์ž‘ํ•œ๋‹ค (Could not open a connection to your authentication agent ์˜ค๋ฅ˜ ๋ฐœ์ƒ์‹œ ์‹œ๋„)

ssh-add -K privateํ‚คํŒŒ์ผ์ด๋ฆ„.pem : privateํ‚คํŒŒ์ผ์„ ssh agent์— ์ถ”๊ฐ€ํ•œ๋‹ค. (agent๋ผ๋Š” ์š”์›์—๊ฒŒ ํ‚คํŒŒ์ผ์„ ๋“ค๋ ค ๋ณด๋‚ธ๋‹ค)

ssh -A -i "publicํ‚คํŒŒ์ผ์ด๋ฆ„.pem" ec2์‚ฌ์šฉ์ž์ด๋ฆ„@public์ธ์Šคํ„ด์Šคipv4์ฃผ์†Œ : public์ธ์Šคํ„ด์Šค ํ‚คํŒŒ์ผ๋กœ public์ธ์Šคํ„ด์Šค์— ์ ‘์†ํ•˜๋˜ -A์˜ต์…˜์œผ๋กœ ssh agent์™€ ํ•จ๊ป˜ ์ ‘์†ํ•œ๋‹ค.

์œ„ ๋ช…๋ น์–ด๋กœ public์ธ์Šคํ„ด์Šค์— ์ ‘์†ํ•œ ๋’ค, ๊ทธ public์ธ์Šคํ„ด์Šค์—์„œ ๋‹ค์‹œ
ssh -i "privateํ‚คํŒŒ์ผ์ด๋ฆ„.pem" ec2์‚ฌ์šฉ์ž์ด๋ฆ„@private์ธ์Šคํ„ด์Šคiipv4์ฃผ์†Œ : privateํ‚คํŒŒ์ผ๋กœ private์ธ์Šคํ„ด์Šค์— ์ ‘์†ํ•œ๋‹ค.