본문 바로가기
서버인프라/리눅스

ssh key 접속

by techwold ted 2022. 10. 26.

지금이야 aws가 많이 알려져 ssh key 접속을 더 많이 사용 하는 듯 하다.

OS를 설치 할 일도 없고...

그래도 기본에 충실해야 하기에 한번 rsa key를 만들고 접속 하는 방법을 설명하려 한다.

[root@test-exchange .ssh]# ssh-keygen -m pem -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:rSYCV9Ou4gyhNKxDvnvxq9tZwLBU36hjmHNrKN9ADig root@test-exchange
The key's randomart image is:
+---[RSA 3072]----+
|     .           |
|    . ..o        |
|   o  oo..       |
|o . *..o .       |
|E*o*.B  S .      |
|*.=== +. .       |
|+o.+=oo.o        |
| .+==+oo         |
| oo+==.          |
+----[SHA256]-----+

이렇게 실행하면 2개의 파일이 생성 되는데

[root@test-exchange .ssh]# ls -al
합계 16
drwx------   2 root root   57 10월 26 13:16 .
dr-xr-x---. 10 root root 4096 10월  7 02:38 ..
-rw-------   1 root root 2459 10월 26 13:16 id_rsa
-rw-r--r--   1 root root  572 10월 26 13:16 id_rsa.pub

id_rsa.pub 파일을 authorized_keys 로 변경하겠다.

[root@test-exchange .ssh]# mv id_rsa.pub authorized_keys

그리고 id_rsa파일은 내 컴퓨터에 복사한다.

방법은 scp를 하거나 아니면 텍스트를 그냥 복사해도 된다.

[root@test-exchange .ssh]# cat id_rsa
-----BEGIN RSA PRIVATE KEY-----
MIIG5QIBAAKCAYEA6wU8quBVPZMB9MiI+Syirtx91T9XwIj/xZOvLIoMLyzIRwMP
CPXcGavDQlgyEG0LNPGUui4z+VePEaorku1gm2YRopPUZyV1kfjEMPGjmU+W0SPV
T5lRFg9SQ5LyIetQEP0vXiMD0cBOpQK2k6ecxn10nWJQK016sCYBbnwKKC59iWoN
r48kYF4o7WtXVJe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yULBjFQyhobv3SOrYTN5ET+Bs5XDftQ=
-----END RSA PRIVATE KEY-----

-----BEGIN RSA PRIVATE KEY-----

MIIG5QIBAAKC/.......

-----END RSA PRIVATE KEY-----

위 BEGIN과 END 까지의 텍스트를 복사해서 내 컴퓨터에 저장한다.

~/Downloads » vi t1.pem
-----BEGIN RSA PRIVATE KEY-----
MIIG5QIBAAKCAYEA6wU8quBVPZMB9MiI+Syirtx91T9XwIj/xZOvLIoMLyzIRwMP
CPXcGavDQlgyEG0LNPGUui4z+VePEaorku1gm2YRopPUZyV1kfjEMPGjmU+W0SPV
T5lRFg9SQ5LyIetQEP0vXiMD0cBOpQK2k6ecxn10nWJQK016sCYBbnwKKC59iWoN
r48kYF4o7WtXVJeR7fpDUVwo9eMcO7tT5/EcoN4BCLT2xmOJkTwUT/GAxLzx0RKK
uyQZFGcBPfoCKTLnViz7QDUzc8RR0WhEVhIti0in6qfC9sLkjm7ld6MlaGkylujN
/NWweyL0dJmrwb3S8PTSlXZ4foq8e4wgh/N6exjuI/KcPE+UwKFEqmdJyv6CV8Hx
6acXZG0EuIuBwjkn+DwhyOOZxV0NALkgFfrPtoL57dDCMmF6AOTDUh3Q6JTceosN
CXQdDjfqqyXttpt1ctBNLb4wcgT2t0tcQuKgPjuVEWql3ZIu1XOqqY+/S/yHsdZ2
bGJY+gT1OVkkTrorAgMBAAECggGBALFI4QvBb9uj8nzRbSnxtsKLR0y+nJZ7gd1r
21+Qv0Iy2N1gfE35ENA4lnGMkC994k9M0TFkuwYjO6RKptYNxKtU4oauVzJ7umWj
r3NwREXZGN6o1jdWYylt41NgHNDjbiFyq/GqHi5yj6DAHDPj40qDxp0WVX1k0+De
uoO6g/rtnvsyiiJdq0YaoWr/ZwBD2ewXtgJAsBFUAa85T0EOy9a5wTPtNp5O5a4u
EPCBL+64zP02rHog795JGVHELy8e2ptAk9/Hbs/w4rZLjPGy1hcZAsFlF21X6DKY
unKOr2Ks8k75DkL6oy3UcX2oS8IUxCK04uE8ER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1E1cXrr/cuumHF4oKwLoV63OXMWE/0vjTyH5f1RuY6BBsQ5RCDgOJMxKz38k
MXqXqhxZbR06wsNRUKIXG2AvlIG9f2F+03zWNUgygeHelhlLpiTJorx2zsDD5puO
zuYuvrWjZN01oiyx5oM+l6dm8La/a84mUDTzbgCPh1o0YMS81QKBwQDAjd3rZH8g
tLtRuvBT4zuXYc6u5C8VLUQnli8wR7RfWAZGgGrYsICDMnZh3S7E4xang+TCq35K
l32YDblTmvG3BPppR5XM2I3kMscn9kRv0WA07eQdaL4ew3UCvFL/JivdKJnPOOo7
kDB1k1uc039MPHVk44EBbCD9qlyoMNu42Bo9VzbR32Wk5+t3JtZgnMPlfvpXDejA
EryRBJ1/SWXDPKp27/1v24oYyULBjFQyhobv3SOrYTN5ET+Bs5XDftQ=
-----END RSA PRIVATE KEY-----

 

이제 ssh 접속을 해보겠다.

~/Downloads » ssh -i t1.pem root@192.168.0.111

 

다들 잘 되나요.... 안되시는 분들 남겨주시면 도와드리겠습니다.

'서버인프라 > 리눅스' 카테고리의 다른 글

Linux sar 모니터링  (0) 2023.02.03
LINUX 장애 디스크 복구  (0) 2023.01.31
SCP 파일 전송  (0) 2022.10.24
사설 아이피 대역  (0) 2022.10.12
Linux Disk resize  (0) 2022.10.09

댓글