리눅스 SSH 패스워드 없이 자동 로그인

(리눅스 SSH 자동로그인에서 넘어옴)

1 개요[ | ]

리눅스 SSH 자동 로그인
암호 없이 SSH 접속
패스워드 입력 없이 SSH 접속
  • 클라이언트에서 서버로 SSH 접속을 패스워드 요구 없이 할 수 있음
  • 클라이언트 측에서 키 생성(ssh-keygen)하여 서버로 배포(ssh-copy-id)하면 됨
  • 아래 예시에서, 클라이언트는 123.45.67.89(zetawiki), 서버는 123.45.67.102(zetawiki02)

2 사전작업[ | ]

root@zetawiki:~# apt-get install sshpass
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  sshpass
0 upgraded, 1 newly installed, 0 to remove and 140 not upgraded.
Need to get 10.5 kB of archives.
After this operation, 56.3 kB of additional disk space will be used.
Get:1 http://us.archive.ubuntu.com/ubuntu/ trusty/universe sshpass amd64 1.05-1 [10.5 kB]
Fetched 10.5 kB in 0s (14.2 kB/s)    
Selecting previously unselected package sshpass.
(Reading database ... 61638 files and directories currently installed.)
Preparing to unpack .../sshpass_1.05-1_amd64.deb ...
Unpacking sshpass (1.05-1) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Setting up sshpass (1.05-1) ...

3 개인키, 공개키 생성[ | ]

ssh-keygen Enter, Enter, Enter, Enter

root@zetawiki:~# ssh-keygen
Generating public/private rsa 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 identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
ed:6b:78:50:2d:69:0b:0d:19:f4:bf:97:ae:a3:bb:30 root@123.45.67.89
The key's randomart image is:
+--[ RSA 2048]----+
|       .oo       |
|        o.       |
|         o.o     |
|        ..*..    |
|        S+.o.    |
|        ...  . . |
|        Eo. . o  |
|        .oo..o   |
|         o=+.o.  |
+-----------------+
→ 개인키 파일 /root/.ssh/id_rsa 생성됨
→ 공개키 파일 /root/.ssh/id_rsa.pub 생성됨

4 서버 로그인 테스트[ | ]

sshpass -p "서버패스워드" ssh root@서버주소
root@zetawiki:~# sshpass -p "P@ssw0rd" ssh 123.45.67.102
Last login: Mon Sep 21 13:11:42 2015 from 123.45.67.89
[root@zetawiki02 ~]# 
[root@zetawiki02 ~]# exit
logout
Connection to zetawiki02 closed.
root@zetawiki:~#

5 공개키를 원격서버에 배포[ | ]

sshpass -p "서버패스워드" ssh-copy-id root@서버주소
root@zetawiki:~# sshpass -p"P@ssw0rd" ssh-copy-id root@123.45.67.102
/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

Number of key(s) added: 1

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

6 로그인 테스트[ | ]

root@zetawiki:~# ssh 123.45.67.102
Last login: Mon Sep 21 13:17:52 2015 from 123.45.67.89
[root@zetawiki02 ~]#

7 같이 보기[ | ]

8 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}