"SSH"의 두 판 사이의 차이

wwiki
이동: 둘러보기, 검색
(ssh config)
(ssh config)
101번째 줄: 101번째 줄:
 
     IdentityFile ~/.ssh/id_rsa
 
     IdentityFile ~/.ssh/id_rsa
 
     UserKnownHostsFile ~/.ssh/known_hosts
 
     UserKnownHostsFile ~/.ssh/known_hosts
 +
    Port 60
 
</syntaxhighlight>
 
</syntaxhighlight>
  
112번째 줄: 113번째 줄:
  
 
윈도우에서는 버전에 따라서 전체경로를 <code>c:/User/[user name]/.ssh/id_rsa</code> 등으로 지정해야 하는 경우가 있다.
 
윈도우에서는 버전에 따라서 전체경로를 <code>c:/User/[user name]/.ssh/id_rsa</code> 등으로 지정해야 하는 경우가 있다.
 +
 +
=== Port ===
 +
기본포트를 변경한 경우에 다음 명령으로 접속할 수 있다.
 +
$ ssh -v 사용자명@서버주소
  
 
== sshd config ==
 
== sshd config ==

2024년 2월 28일 (수) 05:28 판

Secure Shell (SSH)

OpenSSH

https://www.openssh.com/

설치

리눅스

데비안 계열에서 클라이언트 설치

ssh-keygen명령을 포함한다.

$ apt update
$ apt install openssh-client

윈도우

OpenSSH 설치

위의 링크에 있지만, 파워셀을 관리자 권한으로 실행해서 서비스를 제어할 수 있다.

# Start the sshd service
Start-Service sshd

서비스 관리자에서 자동실행을 설정할 수 있다. (서비스명: OpenSSH SSH Server)

OpenSSH 서버 구성

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는 다음 순서로 설정 정보를 얻는다.

  1. command-line options
  2. user's configuration file (~/.ssh/config)
  3. system-wide configuration file (/etc/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 [호스트명]