2015년 1월 27일 화요일

ssh 서버연결

안될때 디버깅 방법
https://help.ubuntu.com/community/SSH/OpenSSH/Keys
서버쪽
sudo service sshd stop
sudo /usr/sbin/sshd -d
클라쪽
ssh -v ( or -vv) username@host's

ssl 접속
로컬
cd ~/.ssh
ssh-keygen -t rsa -C "resoliwan@gmail.com"
vi id_rsa.pub

복사

서버 접속
cd ~/.ssh
authorized_keys 있으면
cp authorized_keys back_up_authorized_keys
authorized_keys 없으면
cat id_rsa.pub >> authorized_keys
chmod go-w ~/
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

vi authorized_keys 또는 cat id_rsa.pub >> authorized_keys
위에 펍키 그냥 추가하기

authorized_keys 권한이 아래와 같은지 확인
-rw------- 1 usreId usreId 1247 2015-01-28 14:18 authorized_keys

.ssh/config
아래와 같이 설정을 추가해서 쓸수 있음
Host ipaddress
HostName ipaddress
User usreId
identityFile ~/.ssh/self


ssh 서버 설정하기(리무트)
[서버에서]
/etc/ssh/sshd_config
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key


RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile      .ssh/authorized_keys
//RSAAuthentication, PubkeyAuthentication을 허용하며  각 유저의 .ssh/authorized_keys 파일에
공개키를 저장하겠음

PasswordAuthentication yes
위에 실패할경우 패스워드 접속을 하겠음

* 옵션별 상세 설명
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
설명
Specifies a file containing a private host key used by SSH.  The
    default is /etc/ssh/ssh_host_key for protocol version 1, and
    /etc/ssh/ssh_host_dsa_key, /etc/ssh/ssh_host_ecdsa_key,
    /etc/ssh/ssh_host_ed25519_key and /etc/ssh/ssh_host_rsa_key for
    protocol version 2.

    사용이유
   To prevent man-in-the-middle attacks, each SSH server has a unique identifying code, called a host key. These keys prevent a server
   from forging another server’s key. If you connect to a server for the first time or if the server presets a different key then
   previously, WinSCP will prompt you to verify the key.

RSAAuthentication yes
RSA 인증을 설정. Protocol 1 에 적용

PubkeyAuthentication yes
공개키 인증 설정. Protocol 2에 적용

AuthorizedKeysFile
공개키 파일명 파일명을 지정
디폴트는 유저의 홈 디렉토리로부터의 상대 패스에서 AuthorizedKeysFile 에 설정되 있는 파일을 공개키 파일로 설

서비스 재시작
service sshd restart

로컬에서 키생성
[로컬에서]
ssh-keygen -t dsa
Enter file in which to save the key (/Users/lee/.ssh/id_dsa):  enter
이름을 지정하면 키 복사시 ssh-copy-id -i path/to/key_name.pub user_name@host_name
연결시 ssh -i path/to/key_name user@host
로 접속 해야 한다.



키 파일 서버에 올리기
[로컬에서]
scp -P 포트 로컬파일 리무트계정@리무트주소:리무트파일

어떻게 동작하는지 알고 싶으면 아래 링크 확인
http://www.parkjonghyuk.net/lecture/modernCrypto/lecturenote/chap05.pdf