ssh_config 설정

개요

ssh 는 명령 옵션을 설정 파일로 만들어 관리 할 수 있는데 이를 이용하면 옵션을 매번칠 필요도 없으며 호스트별 인증서(개인키) 사용할 수 도 있다.

설정 파일

  • 설정 파일은 시스템 전역 파일(/etc/ssh/config_ssh)와 사용자 전용 파일이 있다.
  • 옵션 적용 순서는 명령형 옵션 > 사용자 설정파일 > 시스템 전역 설정 파일 순이다.
  • 각 옵션은 호스트 네임으로 구분되며 포트, 사용자 이름, 인증성 파일 등을 설정 할 수 있다.
  • 다음 ssh 메뉴얼 내용 참고

ssh(1) obtains configuration data from the following sources in the following order:
1. command-line options
2. user's configuration file (~/.ssh/config)
3. system-wide configuration file (/etc/ssh/ssh_config)
For each parameter, the first obtained value will be used. The configuration
files contain sections separated by Host specifications, and that section is
only applied for hosts that match one of the patterns given in the specifica‐
tion. The matched host name is usually the one given on the command line.

여러개 인증서 사용하기

접속하려는 서버의 인증서(개인키)별 호스트명_id_rsd으로 만들어 사용할 수 있으며, ssh로 접속시 사용자 설정파일에 설정한 호스트 네임으로 접속하게 되면 ssh가 해당 인증서를 찾아 ssh 접속을 수행

사용 예

  • 사용자 설정 파일 (~/.ssh/config) 만들기
    • github.com과 blog.host.com 을 ssh로 접속하는 경우
    • 각 서버의 개인키(id_rsa)을 복사 id_rsa와 blog_id_rsa 파일을 만들어 붙어넣음
    • 사용자 설정파일을 생성하여 아래와 같이 작성
    • 더 자세한 내용은 ssh_config man 파일 참고
Host github.com
        User kim
        IdentityFile ~/.ssh/id_rsa
Host blog.host.com
        User igotoo
        Port 2200
        IdentityFile ~/.ssh/blog_id_rsa
  • ssh 접속
ssh igotoo@blog.host.com 

참고 : SSH 인증 여러개 사용하기 ssh_config man 파일

igotoo

igotoo