최신판 |
당신의 편집 |
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 |