SSH KEY 인증을 통한 서버 접속
2020.11.10 04:34
서버간의 접속을 SSH KEY 인증을 통해서 한다.
본인의 SSH 공개키를 서버의 홈계정의 .ssh 폴더의 authorized_keys 에 등록하면 ssh를 통해 비밀번호 없이 바로 접속가능함
1. SSH-KEYGEN
[root@n1 ~]# ssh-keygen
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:+2wVnFCZH6OXdRnIxA8KL/Ac+F1ADM0WvrUkj6EIpcY root@cjn1
The key's randomart image is:
+---[RSA 2048]----+
| ...*=B+..o|
| . oo oo=o*o.o|
| E = **o*o=.|
| . . .=.+& =. |
| .S..o = |
| . . |
| . . |
| o. |
| .o |
+----[SHA256]-----+
2. 생성확인
[root@n1 ~]# ls -al .ssh
합계 16
drwx------ 2 root root 57 11월 10 04:53 .
dr-xr-x---. 16 root root 4096 11월 10 04:49 ..
-rw------- 1 root root 1679 11월 10 04:53 id_rsa
-rw-r--r-- 1 root root 391 11월 10 04:53 id_rsa.pub
-rw-r--r-- 1 root root 353 11월 10 04:50 known_hosts
3. key 서버에 복사
-. 본예는 57.128 서버의 root 계정 / scp , rsync 등으로 수동으로 복사하거나 Ctrl+C,V 해도됨
-. SSH 공개키를 서버의 홈계정의 .ssh 폴더의 authorized_keys 에 등록
[root@n1 ~]# ssh-copy-id root@192.168.57.128
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.57.128's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@192.168.57.128'"
and check to make sure that only the key(s) you wanted were added.
4. 편의를 위해 hosts 파일 등록
[root@n1 ~]# cat >>/etc/hosts
192.168.57.129 n1
192.168.57.128 n2
^Z
5. 접속
[root@n1 ~]# ssh n2
Last login: Tue Nov 10 04:57:20 2020 from 192.168.57.129
[root@n2 ~]#
댓글 0
번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|
5 | How to validate RMAN backup [1] | 남송휘 | 2021.09.30 | 190 |
4 | hostnamectl / 호스트 이름변경 / ubuntu | 남송휘 | 2021.09.29 | 92 |
3 | end_request: I/O error, dev fd0, sector 0 | 남송휘 | 2021.09.29 | 107 |
2 | CIDR 계산 | 남송휘 | 2021.03.29 | 217 |
» | SSH KEY 인증을 통한 서버 접속 | 남송휘 | 2020.11.10 | 725 |