사용자 도구

사이트 도구


linux:ssh

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

양쪽 이전 판 이전 판
다음 판
이전 판
다음 판 양쪽 다음 판
linux:ssh [2019/08/21 14:03]
kwon37xi
linux:ssh [2020/02/26 10:07]
kwon37xi [Private Key 생성]
줄 10: 줄 10:
 ===== Private Key 생성 ===== ===== Private Key 생성 =====
 <code sh> <code sh>
-ssh-keygen -t rsa+ssh-keygen -t rsa -b 4096 -m pem -C "your_email@example.com"
 </code> </code>
   * Passphrase를 항상 넣는 것이 좋다.   * Passphrase를 항상 넣는 것이 좋다.
   * ''id_rsa'' 파일은 개인키로 자신의 PC(Client)에 둔다.   * ''id_rsa'' 파일은 개인키로 자신의 PC(Client)에 둔다.
   * ''*.pub'' 파일은 공개키로 접속 대상 서버 계정의 ''~/.ssh/authorized_keys'' 파일에 그 내용을 추가한다.   * ''*.pub'' 파일은 공개키로 접속 대상 서버 계정의 ''~/.ssh/authorized_keys'' 파일에 그 내용을 추가한다.
-  * ''~/.ssh''에 있는 파일은 ''600'' 권한으로 설정해야한다.+  * [[git:github|Github]] 참조. 
 +  * ''ssh-keygen'' 최근 버전에서 ''-m pem'' 옵션이 없으면 private Key 헤더가 ''%%-----BEGIN OPENSSH PRIVATE KEY-----%%''로 시작한다면 호환 안되는 경우가 있을 수 있다. 
 +  * [[:upsource|Upsource]] 등 일부 과거 시스템들의 호환성으 높이려면 ''-m pem'' 옵션 추가할 것. 헤더가 ''%%-----BEGIN RSA PRIVATE KEY-----%%''로 시작해야한다. 
 +  * ''~/.ssh''에 있는 파일은 ''600'' 권한으로 설정해야한다. 해당 디렉토리도 권한 확인이 필요하다.<code sh> 
 +chmod 700 ~/.ssh 
 +</code>
  
 ===== ssh-agent ===== ===== ssh-agent =====
줄 25: 줄 30:
 </code> </code>
   * 키 등록이 안 될 경우 키 파일의 권한이 **0600**이 맞는지 확인 해 본다.   * 키 등록이 안 될 경우 키 파일의 권한이 **0600**이 맞는지 확인 해 본다.
 +
 +<code sh>
 +chmod 600 ~/.ssh/id_rsa*
 +</code>
   * [[https://unix.stackexchange.com/questions/90853/how-can-i-run-ssh-add-automatically-without-a-password-prompt|ssh agent - How can I run ssh-add automatically, without a password prompt? - Unix & Linux Stack Exchange]]   * [[https://unix.stackexchange.com/questions/90853/how-can-i-run-ssh-add-automatically-without-a-password-prompt|ssh agent - How can I run ssh-add automatically, without a password prompt? - Unix & Linux Stack Exchange]]
  
줄 36: 줄 45:
     * [[http://haruair.com/blog/2219|ssh config로 ssh 접속 간편하게 하기]]     * [[http://haruair.com/blog/2219|ssh config로 ssh 접속 간편하게 하기]]
     * [[http://nerderati.com/2011/03/simplify-your-life-with-an-ssh-config-file/|Simplify Your Life With an SSH Config File]]     * [[http://nerderati.com/2011/03/simplify-your-life-with-an-ssh-config-file/|Simplify Your Life With an SSH Config File]]
 +    * 파일 권한<code sh>
 +chmod 600 ~/.ssh/config
 +</code>
   * ''~/.ssh/config''<code sh>   * ''~/.ssh/config''<code sh>
 # 기본형태. ~/.ssh/id_rsa 를 사용할 경우 혹은 일반 비밀번호 인증의 경우 # 기본형태. ~/.ssh/id_rsa 를 사용할 경우 혹은 일반 비밀번호 인증의 경우
줄 41: 줄 53:
     HostName IP 혹은 hostname     HostName IP 혹은 hostname
     User 계정명     User 계정명
 +    IdentitiesOnly yes
  
 # 특정 key 지정 # 특정 key 지정
줄 48: 줄 61:
     PreferredAuthentications publickey     PreferredAuthentications publickey
     IdentityFile ~/.ssh/[private key]     IdentityFile ~/.ssh/[private key]
 +    IdentitiesOnly yes
  
 # github.com git 계정 접속시에 대한 처리 # github.com git 계정 접속시에 대한 처리
 Host github.com Host github.com
 +    HostName github.com
     User git     User git
     IdentityFile ~/.ssh/[github private key]     IdentityFile ~/.ssh/[github private key]
 +    IdentitiesOnly yes
          
 # 동일 2차 도메인 사용시 # 동일 2차 도메인 사용시
줄 59: 줄 75:
     PreferredAuthentications publickey     PreferredAuthentications publickey
     IdentityFile ~/.ssh/[private key]     IdentityFile ~/.ssh/[private key]
 +    IdentitiesOnly yes
 </code> </code>
   * [[https://gist.github.com/jexchan/2351996|동일 HostName, 동일 User 다중 Key]] ''Host github.com-SSHID'' 에서 ''Host'' 의 값을 ''github.com-myid'' 형태로 특정 값을 줘서 처리할 수 있고, 그 뒤 부터 ssh ''github.com-myid'' 같은 호출이 정상 작동한다.   * [[https://gist.github.com/jexchan/2351996|동일 HostName, 동일 User 다중 Key]] ''Host github.com-SSHID'' 에서 ''Host'' 의 값을 ''github.com-myid'' 형태로 특정 값을 줘서 처리할 수 있고, 그 뒤 부터 ssh ''github.com-myid'' 같은 호출이 정상 작동한다.
 +    * [[https://stackoverflow.com/questions/7927750/specify-an-ssh-key-for-git-push-for-a-given-domain|Specify an SSH key for git push for a given domain - Stack Overflow]]
 +    * [[https://serverfault.com/questions/450796/how-could-i-stop-ssh-offering-a-wrong-key/450807#450807|gitolite - How could I stop ssh offering a wrong key? - Server Fault]] ''IdentitiesOnly yes'' 설정도 주는게 좋다. 그렇지 않으면 우선 순위상에 있는 다른 키 파일들 뒤에 ''IdentityFile''에 설정한 파일이 뒤로 추가되는 형태로 시도된다.(''~/.ssh/id_dsa, ~/.ssh/id_rsa'' 등이 더 우선된다)
  
 ===== 접속 유지 Keep connection ===== ===== 접속 유지 Keep connection =====
linux/ssh.txt · 마지막으로 수정됨: 2023/01/30 17:19 저자 kwon37xi