The Pursuit of Happyness

반응형
이 포스트는 아래 링크에 있는 자료를 요약한 자료 입니다.

http://www.thegeekstuff.com/2008/11/3-steps-to-perform-ssh-login-without-password-using-ssh-keygen-ssh-copy-id/ 



ssh-keygen 과 ssh-copy-id 를 이용하면  패스워드를 입력하지 않고 리눅스 서버에 접속할수 있습니다.

ssh-keygen 은 public / private 키를 생성하는 명령어이고,

ssh-copy-id 는 로컬 호스트에 있는 public 키를 원격 서버에 있는 인증된 키를 저장하는 파일 (authorized_keys)  에 추가해 주는 명령어 입니다.

ssh-copy-id 는 원격 호스트의 홈 폴더에 있는 ~/.ssh 폴더, ~/.ssh/ authorized_keys 파일에 적절한 권한을 부여해줍니다.


1 단계 로컬호스트에서 ssh-key-gen 을 이용하여 public / private 키를 생성하기

userid@local-host$ [Note: You are on local-host here]

userid@local-host$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/userid/.ssh/id_rsa):[Enter key]
Enter passphrase (empty for no passphrase): [Press enter key]
Enter same passphrase again: [Pess enter key]
Your identification has been saved in /home/userid/.ssh/id_rsa.
Your public key has been saved in /home/userid/.ssh/id_rsa.pub.
The key fingerprint is:
73:b4:ee:aa:b5:c5:d8:e1:f1:a5:1e:26:5f:2f:53:9f userid@local-host

2 단계 ssh-copy-id 를 이용해서 원격 서버로 public 키를 복사하기

userid@local-host$ ssh-copy-id -i ~/.ssh/id_rsa.pub remote-host
userid@remote-host's password:
Now try logging into the machine, with "ssh 'remote-host'", and check in:

.ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.
Note: ssh-copy-id 는 원격 서버에 있는 .ssh/authorized_key 에 public 키를 추가해 주는 작업입니다.


3단계 패스워드없이 원격서버에 로그인하기

userid@local-host$ ssh remote-host
Last login: Sun Nov 16 17:22:33 2008 from 192.168.1.2
[Note: SSH did not ask for password.]

userid@remote-host$ [Note: You are on remote-host here]

정리를 해 보면 서버1에서 서버2에 접속하기 위해서는 서버1에서 공용키를 생성해서 서버2에 복사해서 인증을 해 두어야 한다는 것입니다.

맥에서는 ssh-copy-id 라는 명령어가 없기 때문에 ssh-copy-id 에 해당하는 부분은 수동으로 설정을 해야 합니다.

방법은 서버1에서 ssh-keygen 으로 생성한 ~/.ssh/id_rsa.pub 파일을 서버2로 보냅니다. 

scp ~/.ssh/id_rsa.pub remote-host:home/userid

서버2에 로그인 하여, 다음의 명령어를 이용하여 public 키를 추가합니다.

cat ~/id_rsa.pub >> ~/.ssh/authorized_key



반응형