티스토리 뷰

 - bash shell입니다.

 - Ubuntu 환경에서 테스트하였습니다.

 

 

이론

 - 대칭키/비대칭키 암호화 방식 중, 비대칭키 암호화 방식 ( 공개키 )

 - 로컬서버의 공개키를 원격서버로 공유하여 접근

 

사용 가능 범위

 - SSH / SCP / RSYNC 등 SSH 프로토콜을 이용한 모든 일련의 과정

 

설정 방법

local_server1 = 10.20.30.5

remote_server2 = 10.20.30.27

 

로컬 서버 실행 터미널

local_server1$ ssh-copy-id -i ~/.ssh/id_rsa.pub root@10.20.30.27

The authenticity of host '10.20.30.27 (10.20.30.27)' can't be established.
RSA key fingerprint is 23:d8:15:1f:07:af:ac:7b:a8:19:a9:f5:d7:35:a2:22.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.20.30.27' (RSA) to the list of known hosts.
root@10.20.30.27's password:

로컬 서버에서 최초 접근 이후에 원격 서버로 id_rsa.pub라는 자신의 공개키를 원격서버의 ~/.ssh/authorized_keys 파일에 저장합니다.

두 번째 접근부터는 공개키를 이용하여 패스워드 접속 없이 접근이 가능하게 됩니다.

공개키 암호화 방식이기 때문에 id_rsa 라는 사설키(개인키)는 절대로 유출하면 안됩니다.

 

원격 서버 ~/.ssh/authorized_keys 파일 내용

ssh-rsa AAAAB3NaOJ1yc2EAAAABIwABAQEAplB5P0233jrTsQ5zjHHlaFATAVeOJ+(이하생략)== root@10.20.30.27

 

 

 

 - 공개키 암호화 방식입니다. ( 따라서, 원격 서버의 authorized_keys 파일에 등록된 키 값을 지우고, 원격서버로 접속시에는 다시 패스워드를 질의하게 됩니다.)

 - 사설키는 절대로 유출하면 안됩니다.

 - 최초 접근 이후에 두 번째 접속부터는 패스워드 없이 접속이 가능합니다.

 - 각종 스크립트에 활용하기 좋습니다.

 

 

man page

NAME
ssh-copy-id - install your public key in a remote machine’s authorized_keys

SYNOPSIS
ssh-copy-id [-i [identity_file]] [user@]machine

DESCRIPTION
ssh-copy-id is a script that uses ssh to log into a remote machine (presumably  using a login password, so password authentication should be enabled, unless you’ve done some clever use of multiple identities) It also  changes the  permissions  of  the  remote  user’s  home,  ~/.ssh, and ~/.ssh/authorized_keys to remove group writability (which would otherwise  prevent  you from  logging  in, if the remote sshd has StrictModes set in its configuration).  If the -i option is given  then  the  identity  file  (defaults  to ~/.ssh/id_rsa.pub)  is  used,  regardless  of whether there are any keys in your ssh-agent.  Otherwise, if this:       ssh-add -L provides any  output, it uses that in preference to the identity file.  If the -i option is used, or the ssh add produced no output, then it uses the contents of  the  identity  file.   Once  it  has one or more fingerprints (by whatever means) it uses ssh to append them to ~/.ssh/authorized_keys  on  the  remote  machine (creating the file, and directory, if necessary)

SEE ALSO
       ssh(1), ssh-agent(1), sshd(8)

'Linux' 카테고리의 다른 글

grep에 color 입히기  (0) 2020.03.24
history에 명령어 시간 표시하기  (0) 2019.04.20
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함