"SSH"의 두 판 사이의 차이
(→키 생성) |
(→ssh config) |
||
(같은 사용자의 중간 판 29개는 보이지 않습니다) | |||
1번째 줄: | 1번째 줄: | ||
− | + | Secure Shell (SSH) | |
− | |||
− | == | + | == OpenSSH == |
+ | https://www.openssh.com/ | ||
− | === | + | === 설치 === |
==== 리눅스 ==== | ==== 리눅스 ==== | ||
− | $ | + | 데비안 계열에서 클라이언트 설치 |
+ | |||
+ | ssh-keygen명령을 포함한다. | ||
+ | <syntaxhighlight lang="bash"> | ||
+ | $ apt update | ||
+ | $ apt install openssh-client | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | ==== 윈도우 ==== | ||
+ | MS문서: [https://docs.microsoft.com/ko-kr/windows-server/administration/openssh/openssh_install_firstuse OpenSSH 설치] | ||
+ | |||
+ | <code>C:\WINDOWS\System32\OpenSSH\ssh.exe</code>에 설치된다.(8.6.0.1) | ||
+ | |||
+ | 참고로 gitbash에서는(git version 2.44.0.windows.1) <code>C:\Program Files\Git\usr\bin</code>에 설치되며 ssh config파일의 위치도 다른 것으로 보인다. | ||
− | + | [[PowerShell|파워셀]]을 관리자 권한으로 실행해야 서비스를 제어할 수 있다. | |
+ | <syntaxhighlight lang="powershell"> | ||
+ | # Start the sshd service | ||
+ | Start-Service sshd | ||
+ | </syntaxhighlight>서비스 관리자에서 자동실행을 설정할 수 있다. (서비스명: OpenSSH SSH Server) | ||
− | + | [https://docs.microsoft.com/ko-kr/windows-server/administration/openssh/openssh_server_configuration OpenSSH 서버 구성] | |
− | =====[[ | + | Windows에서 sshd는 기본적으로 %programdata%\ssh\sshd_config에서 구성 데이터를 읽습니다. |
+ | |||
+ | 로그를 남기려면 설정파일의 다음부분을 수정한다.<syntaxhighlight lang="apacheconf"> | ||
+ | # Logging | ||
+ | #SyslogFacility AUTH | ||
+ | SyslogFacility LOCAL0 | ||
+ | #LogLevel INFO | ||
+ | LogLevel DEBUG3 | ||
+ | </syntaxhighlight>설정파일의 Match Group administrators에 따라서 __PROGRAMDATA__/ssh/administrators_authorized_keys 파일에서 공개키를 먼저 찾게 되는데(윈도우의 기본설정인 것으로 보인다.) 이 부분을 주석처리해야 리눅스와 동일하게 사용자 폴더의 .ssh/authorized_keys파일에서 공개키를 찾게 된다.<syntaxhighlight lang="apacheconf"> | ||
+ | #Match Group administrators | ||
+ | # AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | === SYNOPSIS === | ||
+ | usage: ssh [-46AaCfGgKkMNnqsTtVvXxYy] [-B bind_interface] | ||
+ | |||
+ | [-b bind_address] [-c cipher_spec] [-D [bind_address:]port] | ||
+ | |||
+ | [-E log_file] [-e escape_char] [-F configfile] [-I pkcs11] | ||
+ | |||
+ | [-i identity_file] [-J [user@]host[:port]] [-L address] | ||
+ | |||
+ | [-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port] | ||
+ | |||
+ | [-Q query_option] [-R address] [-S ctl_path] [-W host:port] | ||
+ | |||
+ | [-w local_tun[:remote_tun]] destination [command] | ||
+ | $ ssh -i .ssh/aws_arm64.pem admin@아이피 | ||
+ | |||
+ | ==ssh-keygen== | ||
+ | authentication key generation, management and conversion | ||
+ | |||
+ | ssh-keygen [-q] [-b bits] [-t dsa | ecdsa | ed25519 | rsa] [-N new_passphrase] [-C comment] [-f output_keyfile] | ||
+ | |||
+ | ===키 생성=== | ||
+ | $ ssh-keygen -t rsa | ||
+ | |||
+ | PS > ssh-keygen -t rsa | ||
+ | 나머지는 엔터치면 기본값으로 .ssh 폴더에 생성된다. | ||
+ | |||
+ | 입력없이 생성하려면 | ||
+ | $ ssh-keygen -q -t rsa -N "" -f /[사용자홈]/.ssh/id_rsa | ||
=====puttygen===== | =====puttygen===== | ||
− | puttygen에서 conversions-> import key | + | [[openssl]] 등을 이용해서 포맷을 변경해야 할 수 있다. |
+ | |||
+ | 외부에서 생성한 개인키를 사용려면(일반적으로 표준이 아니다.)puttygen에서 conversions-> import key | ||
에디터로 열어서 -----BEGIN RSA PRIVATE KEY----- 윗부분은 삭제해야 제대로 로딩된다. | 에디터로 열어서 -----BEGIN RSA PRIVATE KEY----- 윗부분은 삭제해야 제대로 로딩된다. | ||
22번째 줄: | 82번째 줄: | ||
공개키 저장 save public key | 공개키 저장 save public key | ||
− | 저장한 공개키로 ssh에 로그인하려면 base64 인코딩된 부분만 엔터를 지우고 .ssh/authorized_keys 에 추가한다. | + | 저장한 공개키로 ssh에 로그인하려면 base64 인코딩된 부분만 엔터를 지우고 '''.ssh/authorized_keys''' 에 추가한다. |
+ | |||
+ | The Secure Shell (SSH) Public Key File Format: https://datatracker.ietf.org/doc/html/rfc4716 | ||
+ | |||
+ | === 키 관리 === | ||
+ | -e This option will read a private or public OpenSSH key file and print to stdout the key in one of the | ||
+ | |||
+ | formats specified by the -m option. The default export format is “RFC4716”. This option allows ex‐ | ||
+ | |||
+ | porting OpenSSH keys for use by other programs, including several commercial SSH implementations. | ||
+ | $ ssh-keygen -e [-m key_format] [-f input_keyfile] | ||
+ | |||
+ | ==ssh config== | ||
+ | ssh는 다음 순서로 설정 정보를 얻는다. | ||
+ | |||
+ | # command-line options | ||
+ | # user's configuration file (~/.ssh/config) | ||
+ | # system-wide configuration file (/etc/ssh/ssh_config, 윈도우 OpenSSH_for_Windows_8.6p1, LibreSSL 3.4.3 경우에 C:/ProgramData/ssh/ssh_config) | ||
+ | <syntaxhighlight lang="text"> | ||
+ | Host github.com | ||
+ | PreferredAuthentications publickey | ||
+ | IdentityFile ~/.ssh/id_rsa | ||
+ | UserKnownHostsFile ~/.ssh/known_hosts | ||
+ | Port 60 | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | === PreferredAuthentications === | ||
+ | 선호하는 인증방법을 지정한다. | ||
− | = | + | gssapi-with-mic,hostbased,publickey,keyboard-interactive,password |
− | /etc/ssh/sshd_config<syntaxhighlight lang="apacheconf"> | + | |
+ | === IdentityFile === | ||
+ | 기본값은 ''~/.ssh/id_rsa'', ''~/.ssh/id_ecdsa'', ''~/.ssh/id_ecdsa_sk'', ''~/.ssh/id_ed25519'', ''~/.ssh/id_ed25519_sk'' and ''~/.ssh/id_dsa''. 이다. | ||
+ | |||
+ | 윈도우에서는 버전에 따라서 전체경로를 <code>c:/User/[user name]/.ssh/id_rsa</code> 등으로 지정해야 하는 경우가 있다. | ||
+ | |||
+ | === Port === | ||
+ | 기본포트를 변경한 경우에 다음 명령으로 접속할 수 있다. | ||
+ | $ ssh -v 사용자명@서버주소 | ||
+ | |||
+ | == sshd config == | ||
+ | OpenSSH daemon configuration file | ||
+ | |||
+ | ''/etc/ssh/sshd_config''<syntaxhighlight lang="apacheconf"> | ||
# 패스워드 인증허용여부 | # 패스워드 인증허용여부 | ||
− | |||
PasswordAuthentication no | PasswordAuthentication no | ||
</syntaxhighlight> | </syntaxhighlight> | ||
34번째 줄: | 133번째 줄: | ||
===Warning: Permanently added the ECDSA host key for IP address=== | ===Warning: Permanently added the ECDSA host key for IP address=== | ||
− | ip 변경으로 중간자 공격'에 대해 | + | 클라이언트 ip 변경으로 중간자 공격'에 대해 경고이다. |
+ | |||
+ | 클라이언트에서 다음 명령 실행한다. | ||
$ ssh-keygen -R [호스트명] | $ ssh-keygen -R [호스트명] | ||
− | [[분류: | + | [[분류:프로토콜]] |
+ | [[분류:네트워크]] |
2024년 2월 28일 (수) 05:41 기준 최신판
Secure Shell (SSH)
목차
OpenSSH[편집 | 원본 편집]
설치[편집 | 원본 편집]
리눅스[편집 | 원본 편집]
데비안 계열에서 클라이언트 설치
ssh-keygen명령을 포함한다.
$ apt update
$ apt install openssh-client
윈도우[편집 | 원본 편집]
MS문서: OpenSSH 설치
C:\WINDOWS\System32\OpenSSH\ssh.exe
에 설치된다.(8.6.0.1)
참고로 gitbash에서는(git version 2.44.0.windows.1) C:\Program Files\Git\usr\bin
에 설치되며 ssh config파일의 위치도 다른 것으로 보인다.
파워셀을 관리자 권한으로 실행해야 서비스를 제어할 수 있다.
# Start the sshd service
Start-Service sshd
서비스 관리자에서 자동실행을 설정할 수 있다. (서비스명: OpenSSH SSH Server)
Windows에서 sshd는 기본적으로 %programdata%\ssh\sshd_config에서 구성 데이터를 읽습니다.
로그를 남기려면 설정파일의 다음부분을 수정한다.
# Logging
#SyslogFacility AUTH
SyslogFacility LOCAL0
#LogLevel INFO
LogLevel DEBUG3
설정파일의 Match Group administrators에 따라서 __PROGRAMDATA__/ssh/administrators_authorized_keys 파일에서 공개키를 먼저 찾게 되는데(윈도우의 기본설정인 것으로 보인다.) 이 부분을 주석처리해야 리눅스와 동일하게 사용자 폴더의 .ssh/authorized_keys파일에서 공개키를 찾게 된다.
#Match Group administrators
# AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys
SYNOPSIS[편집 | 원본 편집]
usage: ssh [-46AaCfGgKkMNnqsTtVvXxYy] [-B bind_interface]
[-b bind_address] [-c cipher_spec] [-D [bind_address:]port]
[-E log_file] [-e escape_char] [-F configfile] [-I pkcs11]
[-i identity_file] [-J [user@]host[:port]] [-L address]
[-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port]
[-Q query_option] [-R address] [-S ctl_path] [-W host:port]
[-w local_tun[:remote_tun]] destination [command]
$ ssh -i .ssh/aws_arm64.pem admin@아이피
ssh-keygen[편집 | 원본 편집]
authentication key generation, management and conversion
ssh-keygen [-q] [-b bits] [-t dsa | ecdsa | ed25519 | rsa] [-N new_passphrase] [-C comment] [-f output_keyfile]
키 생성[편집 | 원본 편집]
$ ssh-keygen -t rsa
PS > ssh-keygen -t rsa
나머지는 엔터치면 기본값으로 .ssh 폴더에 생성된다.
입력없이 생성하려면
$ ssh-keygen -q -t rsa -N "" -f /[사용자홈]/.ssh/id_rsa
puttygen[편집 | 원본 편집]
openssl 등을 이용해서 포맷을 변경해야 할 수 있다.
외부에서 생성한 개인키를 사용려면(일반적으로 표준이 아니다.)puttygen에서 conversions-> import key
에디터로 열어서 -----BEGIN RSA PRIVATE KEY----- 윗부분은 삭제해야 제대로 로딩된다.
공개키 저장 save public key
저장한 공개키로 ssh에 로그인하려면 base64 인코딩된 부분만 엔터를 지우고 .ssh/authorized_keys 에 추가한다.
The Secure Shell (SSH) Public Key File Format: https://datatracker.ietf.org/doc/html/rfc4716
키 관리[편집 | 원본 편집]
-e This option will read a private or public OpenSSH key file and print to stdout the key in one of the
formats specified by the -m option. The default export format is “RFC4716”. This option allows ex‐
porting OpenSSH keys for use by other programs, including several commercial SSH implementations.
$ ssh-keygen -e [-m key_format] [-f input_keyfile]
ssh config[편집 | 원본 편집]
ssh는 다음 순서로 설정 정보를 얻는다.
- command-line options
- user's configuration file (~/.ssh/config)
- system-wide configuration file (/etc/ssh/ssh_config, 윈도우 OpenSSH_for_Windows_8.6p1, LibreSSL 3.4.3 경우에 C:/ProgramData/ssh/ssh_config)
Host github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
UserKnownHostsFile ~/.ssh/known_hosts
Port 60
PreferredAuthentications[편집 | 원본 편집]
선호하는 인증방법을 지정한다.
gssapi-with-mic,hostbased,publickey,keyboard-interactive,password
IdentityFile[편집 | 원본 편집]
기본값은 ~/.ssh/id_rsa, ~/.ssh/id_ecdsa, ~/.ssh/id_ecdsa_sk, ~/.ssh/id_ed25519, ~/.ssh/id_ed25519_sk and ~/.ssh/id_dsa. 이다.
윈도우에서는 버전에 따라서 전체경로를 c:/User/[user name]/.ssh/id_rsa
등으로 지정해야 하는 경우가 있다.
Port[편집 | 원본 편집]
기본포트를 변경한 경우에 다음 명령으로 접속할 수 있다.
$ ssh -v 사용자명@서버주소
sshd config[편집 | 원본 편집]
OpenSSH daemon configuration file
/etc/ssh/sshd_config
# 패스워드 인증허용여부
PasswordAuthentication no
에러 메시지[편집 | 원본 편집]
Warning: Permanently added the ECDSA host key for IP address[편집 | 원본 편집]
클라이언트 ip 변경으로 중간자 공격'에 대해 경고이다.
클라이언트에서 다음 명령 실행한다.
$ ssh-keygen -R [호스트명]