검색결과 리스트
글
리눅스 ssh-key 생성
ssh-key를 생성하여 서버에 패스워드 없이 접속하기
1. ssh-keygen 명령으로 ssh-key를 생성
- 서버에 접속을 하려는 클라이언트 서버에서 아래와 같이 ssh key를 생성한다. key를 생성하면, 사용자 홈 디렉토리의 .ssh 디렉토리에 id_rsa, id_rsa.pub 두개의 파일이 생성된다.
[root@localhost root]# cd /root/.ssh/
[root@localhost .ssh]# ssh-keygen -t rsa
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:
b5:69:64:dd:16:70:b9:6d:b7:2f:36:da:39:ba:b0:e3 root@jook-test
[root@localhost .ssh]# ls
id_rsa id_rsa.pub known_hosts
2. ssh-key 서버에 복사
- 생성된 id_rsa.pub 파일을 접속하려는 서버내에, 계정 홈 디렉토리에 복사한다. 접속하려는 계정의 홈 디렉토리 .ssh 디렉토리 내에 authorized_keys라는 파일 명으로 복사한다.
여러대의 클라이언트에서 서버에 접속하기 위해서는, 각각의 클라이언트에서 key를 생성하고, id_rsa.pub 파일의 내용을 서버의 authorized_keys 파일에 추가해서 붙여 넣는다
[root@localhost .ssh]# scp id_rsa.pub
192.168.100.32:/root/.ssh/authorized_keys
The authenticity of host '192.168.100.32 (10.10.100.32)' can't be
established.
RSA key fingerprint is 26:fe:28:d9:de:a6:1e:36:2c:73:5e:c2:13:21:c4.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.100.32' (RSA) to the list of known hosts.
root@192.168.100.32's password:
id_rsa.pub 100%
|***************************************************************************|
224 00:00
3. 접속 테스트
- 패스워드 없이 서버에 접속되는지 테스트 한다.
[root@localhost .ssh]# ssh 192.168.100.32
Last login: Tue Jun 24 14:40:23 2008 from 192.168.100.118
[root@localhost ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:50:EA:D4:5C:F3
inet addr:192.168.100.32
Bcast:192.168.101.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST
MTU:1500 Metric:1
RX packets:5668 errors:0 dropped:0
overruns:0 frame:0
TX packets:2536 errors:0 dropped:0
overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:549777 (536.8 KiB) TX
bytes:297273 (290.3 KiB)
Interrupt:16 Base address:0xcc00
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436
Metric:1
RX packets:0 errors:0 dropped:0 overruns:0
frame:0
TX packets:0 errors:0 dropped:0 overruns:0
carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
[root@localhost ~]#
- 서버의 sshd_config(/etc/ssh/sshd_config) 파일에서 아래의 설정부분이 주석처리 되어 있을 경우 ssh-key 적용이 되지 않기 때문에, 주석처리 되어 있다면 주석을 해제한 후 적용한다.
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
'Linux' 카테고리의 다른 글
리눅스 디스크(파티션) 용량 확인 (0) | 2015.10.20 |
---|---|
리눅스 zmodem 설치 및 사용 (0) | 2015.10.20 |
리눅스 시간 수동 설정 (0) | 2015.10.20 |
VI 에디터, GREP 사용시 Tip (0) | 2015.10.20 |
tcpdump 패킷 덤프 (0) | 2015.10.20 |