리눅스 SSH 패스워드 없이 자동 로그인 편집하기

경고: 로그인하지 않았습니다. 편집을 하면 IP 주소가 공개되게 됩니다. 로그인하거나 계정을 생성하면 편집자가 사용자 이름으로 기록되고, 다른 장점도 있습니다.

편집을 취소할 수 있습니다. 이 편집을 되돌리려면 아래의 바뀐 내용을 확인한 후 게시해주세요.

최신판 당신의 편집
1번째 줄: 1번째 줄:
==개요==
;리눅스 SSH 자동 로그인
;암호 없이 SSH 접속
;패스워드 입력 없이 SSH 접속
*클라이언트에서 서버로 SSH 접속을 패스워드 요구 없이 할 수 있음
*클라이언트 측에서 키 생성(ssh-keygen)하여 서버로 배포(ssh-copy-id)하면 됨
*아래 예시에서, 클라이언트는 123.45.67.89(zetawiki), 서버는 123.45.67.102(zetawiki02)
==사전작업==
==사전작업==
*(클라이언트) [[sshpass 설치]]
*[[리눅스 ssh-keygen]]
<syntaxhighlight lang='console'>
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) ...
</syntaxhighlight>
 
==개인키, 공개키 생성==
{{참고|리눅스 ssh-keygen}}
ssh-keygen {{Enter}}, {{Enter}}, {{Enter}}, {{Enter}}
<syntaxhighlight lang='console'>
root@zetawiki:~# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
</syntaxhighlight>
<syntaxhighlight lang='console'>
Enter passphrase (empty for no passphrase):
</syntaxhighlight>
<syntaxhighlight lang='console'>
Enter same passphrase again:
</syntaxhighlight>
<syntaxhighlight lang='console'>
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.  |
+-----------------+
</syntaxhighlight>
:→ 개인키 파일 /root/.ssh/id_rsa 생성됨
:→ 공개키 파일 /root/.ssh/id_rsa.pub 생성됨
 
==서버 로그인 테스트==
<syntaxhighlight lang='bash'>
sshpass -p "서버패스워드" ssh root@서버주소
</syntaxhighlight>
<syntaxhighlight lang='console'>
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:~#
</syntaxhighlight>
 
==공개키를 원격서버에 배포==
{{참고|리눅스 ssh-copy-id}}
<syntaxhighlight lang='bash'>
sshpass -p "서버패스워드" ssh-copy-id root@서버주소
</syntaxhighlight>
<syntaxhighlight lang='console'>
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.
</syntaxhighlight>


==로그인 테스트==
<syntaxhighlight lang='console'>
root@zetawiki:~# ssh 123.45.67.102
Last login: Mon Sep 21 13:17:52 2015 from 123.45.67.89
[root@zetawiki02 ~]#
</syntaxhighlight>


==같이 보기==
==같이 보기==
*[[SSH 자동로그인 막기]]
*[[SSH 자동로그인 막기]]
*[[리눅스 sshpass]]
*[[리눅스 sshpass]]
*[[/root/.ssh/id_rsa]]
*[[/usr/bin/ssh-copy-id: ERROR: No identities found]]


==참고==
==참고 자료==
*http://phpschool.com/gnuboard4/bbs/board.php?bo_table=tipntech&wr_id=72064&page=20
*http://phpschool.com/gnuboard4/bbs/board.php?bo_table=tipntech&wr_id=72064&page=20
*http://opentutorials.org/module/432/3742
*http://opentutorials.org/module/432/3742

제타위키에서의 모든 기여는 크리에이티브 커먼즈 저작자표시-동일조건변경허락 3.0 라이선스로 배포된다는 점을 유의해 주세요(자세한 내용에 대해서는 제타위키:저작권 문서를 읽어주세요). 만약 여기에 동의하지 않는다면 문서를 저장하지 말아 주세요.
또한, 직접 작성했거나 퍼블릭 도메인과 같은 자유 문서에서 가져왔다는 것을 보증해야 합니다. 저작권이 있는 내용을 허가 없이 저장하지 마세요!

취소 편집 도움말 (새 창에서 열림)