1 개요[ | ]
- 리눅스 SSH 자동 로그인
- 암호 없이 SSH 접속
- 패스워드 입력 없이 SSH 접속
- 클라이언트에서 서버로 SSH 접속을 패스워드 요구 없이 할 수 있음
- 클라이언트 측에서 키 생성(ssh-keygen)하여 서버로 배포(ssh-copy-id)하면 됨
- 아래 예시에서, 클라이언트는 123.45.67.89(zetawiki), 서버는 123.45.67.102(zetawiki02)
2 사전작업[ | ]
- (클라이언트) sshpass 설치
Console
Copy
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
Console
Copy
root@zetawiki:~# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Console
Copy
Enter passphrase (empty for no passphrase):
Console
Copy
Enter same passphrase again:
Console
Copy
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 서버 로그인 테스트[ | ]
Bash
Copy
sshpass -p "서버패스워드" ssh root@서버주소
Console
Copy
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 공개키를 원격서버에 배포[ | ]

Bash
Copy
sshpass -p "서버패스워드" ssh-copy-id root@서버주소
Console
Copy
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 로그인 테스트[ | ]
Console
Copy
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 참고[ | ]
편집자 112.149.71.17 Jmnote Jmnote bot 115.94.45.44
로그인하시면 댓글을 쓸 수 있습니다.
Jmnote 2014-11-18
… 2014-11-11
CentOS JDK 설치 ― …CentOS JDK 설치 ― ElliottCentOS vsftpd 설치 및 설정 ― …CentOS에서 apt-get 실행해보기 ― …CentOS에서 apt-get 실행해보기 ― 다미안VirtualBox 리눅스 인터넷 연결 ― …VirtualBox 리눅스 인터넷 연결 ― JmnoteVirtualBox 리눅스 인터넷 연결 ― …리눅스 CPU 사용률 확인 ― 동원잉리눅스 JDK 버전 확인 ― …리눅스 JDK 버전 확인 ― Jmnote리눅스 SSH 패스워드 없이 자동 로그인 ― …리눅스 SSH 패스워드 없이 자동 로그인 ― Jmnote리눅스 날짜 기준으로 파일 삭제하기 ― 백승현리눅스 날짜 기준으로 파일 삭제하기 ― Jmnote리눅스 디렉토리 용량 확인 du ― …리눅스 메모리 사용률 확인 ― 최재완리눅스 메모리 사용률 확인 ― Jmnote좀비 프로세스 찾기, 죽이기 ― 불량펭귄