주 메뉴 열기

wwiki β

SSH

Jhkim (토론 | 기여)님의 2022년 5월 22일 (일) 01:45 판 (자동로그인)

Secure Shell (SSH)

OpenSSH

리눅스

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

ssh-keygen명령을 포함한다.

$ apt update
$ apt install openssh-client

윈도우

OpenSSH 설치

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

# Start the sshd service
Start-Service sshd

서비스 관리자에서 자동실행을 설정할 수 있다.

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

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

나머지는 엔터치면 기본값으로 .ssh 폴더에 생성된다.

입력없이 생성하려면

$ ssh-keygen -q -t rsa -N "" -f /[사용자홈]/.ssh/id_rsa

윈도우

파워쉘에서 생성할 수 있다.

PS > ssh-keygen -t 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]

목차

설정파일

/etc/ssh/sshd_config

# 패스워드 인증허용여부
PasswordAuthentication no

에러 메시지

Warning: Permanently added the ECDSA host key for IP address

클라이언트 ip 변경으로 중간자 공격'에 대해 경고이다.

클라이언트에서 다음 명령 실행한다.

$ ssh-keygen -R [호스트명]