[사례] SSH 공개키 수동 설정 문의 > LINUX 자료실

본문 바로가기
사이트 내 전체검색

LINUX 자료실

[사례] SSH 공개키 수동 설정 문의

페이지 정보

profile_image
작성자 장성욱
댓글 0건 조회 1,651회 작성일 25-03-17 17:52

본문

문서 작성일

원본 작성

 2025/03/17

 

  

[사례] 공개키 설정 문의

문의사항

 dbvpn 계정에서 oracle 패스워드 없이 계정 접속 방법 문의

추가확인사항

 1) oracle 계정의 패스워드 정보 X  → ssh-copy-id 명령어 사용 X (즉, 키 복사 명령어 사용 X)

 2) root 계정 접속 가능                → su - oracle 명령어로 oracle 계정으로 전환 가능

문의회신

 1) 공개키 설정으로 oracle 계정으로 패스워드 없이 접속 가능 

 2) dbvpn 계정에서 공개키 설정 후 root 계정으로 우회하여 oracle 계정에 authoried.key 등록

 

위의 사용 요건을 맞추기 위하여 아래와 같이 테스트 진행하였습니다.

 

1. 테스트 환경

일반계정1

 oracle2 (패스워드 X)

일반계정2

 oracle1 (패스워드 O)

일반계정3

 dbvpn

OS Version

 RHEL 8.1 (단일 호스트, 192.168.10.81/24)

 

 

2. 작업절차1 (dvpn - oracle1) - 패스워드 O

2-1) dbvpn 계정 SSH키 공개키 생성

 

// 기본 설정으로 공개키생성 (설정없이 Enter)

[dbvpn@localhost ~]$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/dbvpn/.ssh/id_rsa):
Created directory '/home/dbvpn/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/dbvpn/.ssh/id_rsa.
Your public key has been saved in /home/dbvpn/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:nf5FeT6+CiqIGl0Lmmn4qN8qs1vYJ+w1oBP9yKyhjPE dbvpn@localhost.localdomain
The key's randomart image is:
+---[RSA 3072]----+
|                 |
|                 |
|                 |
| .       . .   . |
|. o. .  S o   o .|
|.O=+o .  .   . o |
|B*O.*..   ..  ...|
|B@.* o .  ..... .|
|XOE..   ..  ...o.|
+----[SHA256]-----+

 

// 공개키 생성 확인

[dbvpn@localhost ~]$ ll /home/dbvpn/.ssh/
total 8
-rw-------. 1 dbvpn dbvpn 2610 Mar 15 01:17 id_rsa          // 개인키
-rw-r--r--. 1 dbvpn dbvpn  581 Mar 15 01:17 id_rsa.pub     // 공개키

 

2-2) dbvpn 계정에서 oracle1 계정으로 공개키 복사

 

// 키 복사 시 [계정명]:[호스트IP or 네임]

[dbvpn@localhost ~]$ ssh-copy-id oracle1@192.168.10.81
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/dbvpn/.ssh/id_rsa.pub"
The authenticity of host '192.168.10.81 (192.168.10.81)' can't be established.
ECDSA key fingerprint is SHA256:hCzNmHG4O38CCI1/mi7bAT34MNWjz7OjzVe106HNDGA.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
/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
oracle1@192.168.10.81's password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'oracle1@192.168.10.81'"
and check to make sure that only the key(s) you wanted were added.

 

2-3) dbvpn 계정에서 oracle1 계정으로 패스워드 없이 원격 접속 여부 확인

 

// 패스워드없이 계정 접속 확인

[dbvpn@localhost ~]$ ssh oracle1@192.168.10.81
Activate the web console with: systemctl enable --now cockpit.socket

This system is not registered to Red Hat Insights. See https://cloud.redhat.com/
To register this system, run: insights-client --register

Last login: Sat Mar 15 01:20:47 2025 from 192.168.10.1

 

// oracle1 계정 정보 확인1

[oracle1@localhost ~]$ whoami
oracle1

 

// oracle2 계정 정보 확인2

[oracle1@localhost ~]$ id
uid=1002(oracle1) gid=1002(oracle1) groups=1002(oracle1) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023

 

 

※1차 정리※

 

1) 공개키 설정 방법을 통해서 어떻게 키가 생성이 되었는지 출력 결과를 확인해보겠습니다.

 

 

-----------------------------------------------------------------------------------------------------------------------------

@dbvpn

-----------------------------------------------------------------------------------------------------------------------------

 

[dbvpn@localhost ~]$ ll /home/dbvpn/.ssh/
total 12
-rw-------. 1 dbvpn dbvpn 2610 Mar 15 01:17 id_rsa
-rw-r--r--. 1 dbvpn dbvpn  581 Mar 15 01:17 id_rsa.pub
-rw-r--r--. 1 dbvpn dbvpn  175 Mar 15 01:28 known_hosts

 

-----------------------------------------------------------------------------------------------------------------------------

@oracle1

-----------------------------------------------------------------------------------------------------------------------------

 

[oracle1@localhost ~]$ ls -ld /home/oracle1/.ssh/
drwx------. 2 oracle1 oracle1 29 Mar 15 01:28 /home/oracle1/.ssh/

 

[oracle1@localhost ~]$ ll /home/oracle1/.ssh/
total 4
-rw-------. 1 oracle1 oracle1 581 Mar 15 01:28 authorized_keys

----------------------------------------------------------------------------------------------------------------------------- 

 

2) dbvpn 계정의  /home/dbvpn/.ssh/id_rsa.pub 과 oracle1 계정의 /home/oracle1/.ssh/authorized_keys 내용이 동일합니다.

3) 즉, dbvpn 계정의 /home/dbvpn/.ssh/id_rsa.pub 파일이 oracle1 계정의 /home/oracle1/.ssh/authorized_keys 로 복사됩니다.

4) 두 키 값의 동일 여부를 확인후 패스워드 없이 접속이 되는 것을 확인할 수 있습니다.

5) 해당 결과를 바탕으로 oracle2 계정에 키생성 설정을 수동으로 해보겠습니다.

 

 

 

3. 작업절차2 (dvpn - oracle2) - 패스워드 X

3-1) dbvpn 계정 SSH키 생성

 

작업절차1의 공개키와 동일합니다. (위의 작업절차1을 확인 부탁드립니다.)

 

3-2) root 계정 접속 후 /home/oracle2/.ssh 숨김 디렉토리 생성

 

// 계정 전환

[root@localhost ~]# su - oracle2

 

// .ssh 숨김 디렉토리 생성 (휴먼 에러 방지를 위한 절대경로로 생성 권고)

[oracle2@localhost ~]$ mkdir /home/oracle2.ssh

 

// 디렉토리 권한, 소유자 확인 후 변경

[oracle2@localhost ~]$ chmod 700 /home/oracle2/.ssh

[oracle2@localhost ~]$ chown oracle2.oracle2 /home/oracle2/.ssh

[oracle2@localhost ~]$ ls -ld /home/oracle2/.ssh

drwx------. 2 oracle2 oracle2 6 Mar 15 01:56 /home/oracle2/.ssh

 

// authorized_keys 추가

[oracle2@localhost ~]$ vim /home/oracle2/.ssh/authorized_keys

 

 /home/dbvpn/.ssh/id_rsa.pub 파일 내용을 추가 후 저장 (:wq)

 

// authorized_keys 권한, 소유자 변경

[oracle2@localhost ~]$ chmod 600 /home/oracle2/.ssh/authorized_keys

[oracle2@localhost ~]$ chown oracle2.oracle2 /home/oracle2/.ssh/authorized_keys

[oracle2@localhost ~]$ ls -l /home/oracle2/.ssh/authorized_keys
-rw-------. 1 oracle2 oracle2 581 Mar 15 02:06 /home/oracle2/.ssh/authorized_keys

 

3-3) dbvpn 계정에서 oracle1 계정으로 패스워드 없이 원격 접속 여부 확인

 

// 패스워드없이 계정 접속 확인

[dbvpn@localhost ~]$ ssh oracle2@192.168.10.81
Activate the web console with: systemctl enable --now cockpit.socket

This system is not registered to Red Hat Insights. See https://cloud.redhat.com/
To register this system, run: insights-client --register

Last login: Sat Mar 15 01:56:41 2025

 

// oracle2 계정 정보 확인1

[oracle2@localhost ~]$ whoami
oracle2

 

// oracle2 계정 정보 확인2
[oracle2@localhost ~]$ id
uid=1003(oracle2) gid=1003(oracle2) groups=1003(oracle2) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023

 

 

4. 최종정리

 

 1) SSH 공개키 설정을 통해 접속하고자 하는 계정을 패스워드 없이 계정 접속이 가능합니다.

 2) 하지만, SSH 공개키 복사를 위해서는 접속하고자 하는 계정의 패스워드 정보가 필수입니다. 

 3) 공개키 복사 명령어(ssh-copy-id) 사용 불가 시 공개키(id_rsa.pub) 생성 후 접속하고자 하는 계정에 복사키(authorized_keys) 를 생성 합니다.

 4) 위의 과정을 이해하려면 [1] 공개키 설정 방법 [2] 설정 후 적용 결과 숙지 [3] 수동 작업에 대한 메뉴얼을 이해하는 것을 권장합니다.

 

댓글목록

등록된 댓글이 없습니다.

회원로그인

회원가입

사이트 정보

회사명 : (주)리눅스데이타시스템
대표이사 : 정정모
본사 : 강남구 봉은사로 114길 40 홍선빌딩 2층
- tel : 02-6207-1160
대전지사 : 유성구 노은로174 도원프라자 5층
- tel : 042-331-1161

접속자집계

오늘
2,331
어제
2,585
최대
8,445
전체
2,034,541
Copyright © www.linuxdata.org All rights reserved.