티스토리 뷰
finger print로 상호 신뢰하기
Terminal과 Server간에 상호 신뢰하는 방법은 아래와 같습니다.
- Terminal에서 Server를 접근을 시도 합니다. 2가지 방식으로 인증할 수 있습니다.
- id / pw 입력
- private key파일 이용 : Terminal에 서버접근을 위한 SSH private key파일이 있어야 하고, config파일에 정의되어 있어야 함
- Local의 ~/.ssh/known_hosts에 있는 finger print와 대상서버의 /etc/ssh/ssh_host_ecdsa_key.pub의 finger print가 동일한 지 검사합니다. Local에 없는 경우는 접근 여부를 묻고, 틀린 경우는 로그인을 중단합니다.
- 인증이 성공하면 Local termianl의 ~/.ssh디렉토리에 known_hosts파일에 서버의 finger print를 추가합니다.
finger print 예제
local의 ~/.ssh/known_hosts
❯ cd ~/.ssh/
~/.ssh
❯ cat known_hosts
169.56.96.107 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBHHCokG/iL8drxAVi7m+Os/k1L/wVLoSEOUT8UV5ET7W6rkh5TyLObkUjhZbeycpF2RMMBLtc085Jz7LcKUqb0I=
169.56.102.183 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBBf1k6NhjQeVgrIZ6qKKkiH9oX+rb4+RvHWf3gk33loWJp81iXh2mdQG8xVjQDA6IJ96O8UbBElKFGT6ADqTztM=
169.56.96.107서버의 /etc/ssh/ssh_host_ecdsa_key.pub
[root@bastion ~]# cat /etc/ssh/ssh_host_ecdsa_key.pub
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBHHCokG/iL8drxAVi7m+Os/k1L/wVLoSEOUT8UV5ET7W6rkh5TyLObkUjhZbeycpF2RMMBLtc085Jz7LcKUqb0I= root@bastion.ibm.cloud
169.56.102.183서버의 /etc/ssh/ssh_host_ecdsa_key.pub
[ocean@study systemd]$ cat /etc/ssh/ssh_host_ecdsa_key.pub
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBBf1k6NhjQeVgrIZ6qKKkiH9oX+rb4+RvHWf3gk33loWJp81iXh2mdQG8xVjQDA6IJ96O8UbBElKFGT6ADqTztM=
key-based 인증
RSA key로 서버 접근을 인증하는 방법은 happycloud-lee.tistory.com/145 글의 '응용하기'를 참고하십시오
ssh key 생성
key based 접근을 위한 ssh key생성에 대해서는 아래 글을 참조하십시오.
SSH Key 구성
ssh key생성 명령은 ssh-keygen입니다.
먼저 ssh로 접근할 os user로 전환한 후 key를 생성하시는 겁니다.
[root@bastion ssh]# su - hklee
Last login: Thu Jun 4 03:13:24 CDT 2020 from 211.250.162.208 on pts/5
[hklee@bastion ~] $ ssh-keygen -t rsa -b 4096 -C "kubepia ssh key"
-t: type
-b: bit
-C: comments
ssh key를 생성하여 key based로 서버에 접근하는 실습을 해보겠습니다.
-
test user생성 및 전환
[root@bastion ssh]# useradd ocean [root@bastion ssh]# passwd ocean Changing password for user ocean. New password: Retype new password: passwd: all authentication tokens updated successfully. [root@bastion ssh]# su - ocean [ocean@bastion ~]$
-
ssh key생성 및 public key 현재 서버에 복사
[ocean@bastion ~]$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/ocean/.ssh/id_rsa):
Created directory '/home/ocean/.ssh'.
[ocean@bastion ~]$ cd ~/.ssh
[ocean@bastion .ssh]$ ls -l
total 8
rw-------. 1 ocean ocean 1679 Jun 4 03:42 id_rsa
rw-r--r--. 1 ocean ocean 405 Jun 4 03:42 id_rsa.pub
- public key를 복사하여 authorized_keys파일을 생성함
$ ssh-copy-id -i ./id_rsa.pub ocean@10.178.41.148
...
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'ocean@10.178.41.148'"
and check to make sure that only the key(s) you wanted were added.
- Local terminal에 private key 생성 및 ssh config 파일 설정
Local teminal에서 작업합니다.
❯ cd ~/.ssh/keys
~/.ssh/keys
❯ scp kubepia:/home/hklee/.ssh/id\_rsa kubepia\_ocean
/etc/profile.d/lang.sh: line 19: warning: setlocale: LC\_CTYPE: cannot change locale (UTF-8): No such file or directory
id\_rsa 100% 1679 219.3KB/s 00:00
~/.ssh/keys
❯ cd ..
~/.ssh
❯ vi config
Host kubepia
HostName 169.56.96.107
User root
IdentityFile ~/.ssh/keys/kubepia\_rsa
Host kubeocean
HostName 169.56.96.107
User ocean
IdentityFile ~/.ssh/keys/kubepia\_ocean
- Local terminal에서 ssh로 접근
❯ ssh kubeocean Last login: Thu Jun 4 03:58:31 2020 from 211.250.162.208 -bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory [ocean@bastion ~]$ [ocean@bastion ~]$ [ocean@bastion ~]$ pwd /home/ocean
ssh-agent, ssh-add 명령
ssh-keygen명령으로 key 생성시에 key에 대한 암호를 지정할 수 있습니다.
만약 key암호를 지정하면 ssh로 접근할 때마다 key에 대한 암호를 물어봅니다.
이러한 불편함을 없애려면 ssh-agent를 실행하고 ssh-add로 private key파일을 복사하면 됩니다.
ssh-agent는 백그라운드 프로세스로 실행되어 ssh접속 시 ssh private key 암호를 묻지 않도록 해줍니다.
ssh-agent실행하기
$ eval "$(ssh-agent -s)"
ssh-agent에 ssh private key 복사하기
$ ssh-add ~/.ssh/id_rsa
ssh configuration
ssh의 설정을 운영 상황에 맞게 수정합니다.
/etc/ssh/sshd_config파일에서 아래 3가지를 수정합니다.
AllowGroups는 기본으로는 없는 항목이므로 추가하십시오.
ssh접근을 허용할 user group명을 지정합니다. 당연히 이 그룹은 만들어져야 있어야 합니다.
- PermitRootLogin no
- PasswordAuthentication no
- AllowGroups sshusers
[root@bastion ssh]# cd /etc/ssh/
[root@bastion ssh]# ls -l
total 616
-rw-r--r--. 1 root root 581843 Aug 8 2019 moduli
-rw-r--r--. 1 root root 2276 Aug 8 2019 ssh_config
-rw-------. 1 root root 672 Jun 3 00:00 ssh_host_dsa_key
-rw-r--r--. 1 root root 612 Jun 3 00:00 ssh_host_dsa_key.pub
-rw-------. 1 root root 227 Jun 3 00:00 ssh_host_ecdsa_key
-rw-r--r--. 1 root root 184 Jun 3 00:00 ssh_host_ecdsa_key.pub
-rw-------. 1 root root 419 Jun 3 00:00 ssh_host_ed25519_key
-rw-r--r--. 1 root root 104 Jun 3 00:00 ssh_host_ed25519_key.pub
-rw-------. 1 root root 1675 Jun 3 00:00 ssh_host_rsa_key
-rw-r--r--. 1 root root 404 Jun 3 00:00 ssh_host_rsa_key.pub
-rw-------. 1 root root 3906 Dec 10 09:03 sshd_config
[root@bastion ssh]# vi sshd_config
...
Authentication:
#LoginGraceTime 2m
PermitRootLogin no
...
To disable tunneled clear text passwords, change to no here!
PasswordAuthentication no
#PermitEmptyPasswords no
AllowGroups sshusers
...
[root@bastion ssh]# systemctl reload sshd
[root@bastion ssh]#
'Infrastructure > OS' 카테고리의 다른 글
Red Hat System Administration I: Logs (0) | 2020.06.08 |
---|---|
Red Hat System Administration I: timedatectl (0) | 2020.06.08 |
Red Hat System Administration I: Service와 Daemon 관리 (0) | 2020.06.04 |
Red Hat System Administration I: Linux processes (0) | 2020.06.04 |
Red Hat System Administration I: 파일 권한 제어 (0) | 2020.06.03 |
- Total
- Today
- Yesterday
- SAGA
- 돌봄경제
- CQRS
- 애자일
- 도파밍
- API Composition
- 스핀프로젝트
- 마이크로서비스
- 리퀴드폴리탄
- 요즘남편 없던아빠
- AXON
- agile
- spotify
- 분초사회
- 마이크로서비스 패턴
- micro service
- 버라이어티가격
- 스포티파이
- 육각형인간
- 호모프롬프트
- 디토소비
- Event Sourcing
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |