Pages

2/03/2014

Enable ssh login without password(공개키 인증)

linux를 사용하다보면면 공개키인증으로 패스워드없이 로그인해야될때가 있다.(혹은 그냥하고싶을때도 있다..콜록)
그러나 우리는 망각의 동물 항상 까먹는다....
정리해 놓자...^^

centos에서 start@12.12.12.12에서 destination@34.34.34.34로 인증없이 접속한다고 가정하겠다.
공개키 인증은 사설키를 가지고 배포한 공개키로 조합하여 인증을 한다.
공개키와 사설키를 만들자.

$ssh start@12.12.12.12
start@12.12.12.12's password:
Last login: Mon Feb  3 09:47:08 2014 from 111.223.54.49
#if ~/.ssh doesn't exist
#you should make '.ssh' directory.(mkdir ~/.ssh)
$cd ~/.ssh/
$ssh-keygen -t rsa

#if you want a defualt value, push enter!!
Generating public/private rsa key pair.
Enter file in which to save the key (/home/start/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/start/.ssh/id_rsa.
Your public key has been saved in /home/start/.ssh/id_rsa.pub.
The key fingerprint is:
60:20:69:d4:64:8a:29:3a:1b:3d:d8:1d:0e:7b:59:7e silapps@e297d92a-7cf3-40be-8085-f344091a98eb
The key's randomart image is:
+--[ RSA 2048]----+
| .o++            |
| oo+..           |
|+.o . +          |
|o+ = * .         |
|= = = . E        |
| + o   .         |
|.                |
|                 |
|                 |
+-----------------+
공개키와 사설키가 생성되었다. 이제 공개키를 destination에 배포하자.

destination서버에도 .shh 디렉토리가 없다면 생성해주자.
$ssh destination@34.34.34.34 mkdir -p .ssh
$cat ~/.ssh/id_rsa.pub | ssh destination@34.34.34.34 'cat >> .ssh/authorized_keys'
destination에 공개키인증으로 접속 할 수 있도록 설정해주자.
$ssh destination@34.34.34.34
$sudo vi /etc/ssh/sshd_config
# 주석을 풀어준다.
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile     .ssh/authorized_keys

$sudo service sshd restart
#권한 설정
$chmod 700 ~/.ssh
$chmod 600 ~/.ssh/authorized_keys
끄읕~ 테스트해보자.
$ssh start@12.12.12.12
$ssh destination@34.34.34.34
Last login: Mon Feb  3 16:46:54 2014 from 12.12.12.12
$
성공~

0 개의 댓글:

댓글 쓰기