주 메뉴 열기

wwiki β

바뀜

SSH

4,385 바이트 추가됨, 2024년 2월 28일 (수)
ssh config
== Secure Shell (SSH using Linux or Mac OS ==https://www.raspberrypi.org/documentation/remote-access/ssh/unix.md)
== 자동로그인 OpenSSH ==https://www.openssh.com/
=== 키 생성 설치 ===$ ssh-keygen -t rsa
나머지는 엔터치면 기본값으로 ==== 리눅스 ====데비안 계열에서 클라이언트 설치 ssh-keygen명령을 포함한다.ssh 폴더 생성<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
===== [[openssl]] ===== 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)<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 === 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
</syntaxhighlight>
= 에러 메시지 = ===Warning: Permanently added the ECDSA host key for IP address===클라이언트 ip 변경으로 중간자 공격'에 대해 경고이다.
=== Warning: Permanently added the ECDSA host key for IP address ===ip 변경으로 중간자 공격'에 대해 경고클라이언트에서 다음 명령 실행한다.
$ ssh-keygen -R [호스트명]
[[분류:Linux프로토콜]][[분류:네트워크]]
편집
2,431