2020. 7. 16.

[Linux] SSH_key


*SSH - KEY

공개키를 미리 저장하고 공개키를 이용한 인증방식이다.

과정
  1. 클라이언트에서 키생성.
  2. 공개키를 서버로 이전
  3. 패스워드 없는 접속 테스트

1. 클라이언트에서 키 생성

# ssh-keygen -t <type> -b <bits>
-t : rsa, dsa
-b : rsa(768~2048), dsa(1024)

# ssh—keygen 
Generat ing publ ic/pr ivate r sa 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 ident ificat ion has been saved in / roo /.ssh/ id_rsa. 
Your publ ic key has been saved in /root/ .ssh/id_rsa . pub. 
The key fingerprint is. 
root@att-c6 
The key's randomart image is: 
RSA

// fingerprinter 통해 해시코드를 이용한 무결성 검증
// 개인키, 공개키

2. 공개키를 서버로 이전

# ssh-copy-id 계정@IP

# ssh—copy—id root@centos7 
1192.168.10.55 (192.168.10.55)' can't be establ ished. 
The authenticity of host 
RSA key fingerprint is 72:df 
Are you sure you want to cont inue connect ing (yes/no)? yes 
Warning: Permanently added 1192.168. 10.55' (RSA) to the list of known hosts. 
roo @192.168.10.551s password 
Now try logging in o the machine, with "ssh 'root@192.168. 10.55' 
and check in: 
. ssh/author i zed_keys 
to make sure we haven't added extra keys ha you weren't expect ing. 
, SSfi/GbItfiorized_keys Oil

// 한번 접속을 해서 공개키를 서버로 이전시켜야한다.
// 저장파일이 만들어진다.
// 덮어쓰기하면안된다. 마우스로 드래그해서 복사 붙여넣기를 해야한다.

3. 접속 확인

# ssh root@192.168.10.55
Last login: Wed Jul 15 10:27:46 2020 from 192.168.10.3

# ← 패스워드 없이 바로 접속된다.

/etc/ssh/sshd_config
#PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
- 기본 값으로 수정할 필요 없다.
#PasswordAuthentication yes
- no로 바꾸면 패스워드 인증이 거부된다. key를 이용한 접속만 가능하다.
주석이 default 값이다.
// 집에서 혼자 쓴다면 패스워드인증을 no 바꾸고 키가 있는곳에서만 사용


댓글 없음:

댓글 쓰기