문서의 선택한 두 판 사이의 차이를 보여줍니다.
양쪽 이전 판 이전 판 다음 판 | 이전 판 다음 판 양쪽 다음 판 | ||
linux:ssh [2015/04/09 16:46] kwon37xi [sshpass] |
linux:ssh [2023/01/30 16:58] kwon37xi |
||
---|---|---|---|
줄 5: | 줄 5: | ||
* [[http:// | * [[http:// | ||
* [[http:// | * [[http:// | ||
+ | * [[linux: | ||
+ | * [[linux: | ||
+ | * [[linux: | ||
+ | * [[: | ||
+ | * [[linux: | ||
+ | * [[linux: | ||
+ | * [[linux: | ||
===== Private Key 생성 ===== | ===== Private Key 생성 ===== | ||
<code sh> | <code sh> | ||
- | ssh-keygen -t rsa | + | ssh-keygen -t rsa -b 4096 -m pem -C " |
</ | </ | ||
* Passphrase를 항상 넣는 것이 좋다. | * Passphrase를 항상 넣는 것이 좋다. | ||
* '' | * '' | ||
* '' | * '' | ||
- | * '' | + | |
+ | * '' | ||
+ | * [[: | ||
+ | | ||
+ | chmod 700 ~/.ssh | ||
+ | </ | ||
+ | |||
+ | ==== 서버의 '' | ||
+ | * [[https:// | ||
+ | |||
+ | <code sh> | ||
+ | ssh-copy-id -f -i id_rsa.pub username@host | ||
+ | </ | ||
===== ssh-agent ===== | ===== ssh-agent ===== | ||
줄 24: | 줄 43: | ||
* 키 등록이 안 될 경우 키 파일의 권한이 **0600**이 맞는지 확인 해 본다. | * 키 등록이 안 될 경우 키 파일의 권한이 **0600**이 맞는지 확인 해 본다. | ||
+ | <code sh> | ||
+ | chmod 600 ~/ | ||
+ | </ | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[linux: | ||
+ | ===== ssh-agent forwarding ===== | ||
+ | * local PC 에 원격 서버의 private key 를 두고, 이를 bastion 서버에 그대로 포워딩해주고, | ||
+ | * 이렇게 하면 공용 bastion 서버에 private key를 두지 않기 때문에 좀 더 안전해진다. | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * '' | ||
===== SSH 접속 인사 텍스트 ===== | ===== SSH 접속 인사 텍스트 ===== | ||
* ''/ | * ''/ | ||
+ | * 그런데 '' | ||
+ | * 따라서 '' | ||
===== ~/ | ===== ~/ | ||
줄 32: | 줄 67: | ||
* [[http:// | * [[http:// | ||
* [[http:// | * [[http:// | ||
+ | * 파일 권한< | ||
+ | chmod 600 ~/ | ||
+ | </ | ||
* '' | * '' | ||
# 기본형태. ~/ | # 기본형태. ~/ | ||
줄 37: | 줄 75: | ||
HostName IP 혹은 hostname | HostName IP 혹은 hostname | ||
User 계정명 | User 계정명 | ||
+ | IdentitiesOnly yes | ||
# 특정 key 지정 | # 특정 key 지정 | ||
줄 44: | 줄 83: | ||
PreferredAuthentications publickey | PreferredAuthentications publickey | ||
IdentityFile ~/ | IdentityFile ~/ | ||
+ | IdentitiesOnly yes | ||
# github.com git 계정 접속시에 대한 처리 | # github.com git 계정 접속시에 대한 처리 | ||
Host github.com | Host github.com | ||
+ | HostName github.com | ||
User git | User git | ||
IdentityFile ~/ | IdentityFile ~/ | ||
+ | IdentitiesOnly yes | ||
| | ||
# 동일 2차 도메인 사용시 | # 동일 2차 도메인 사용시 | ||
줄 55: | 줄 97: | ||
PreferredAuthentications publickey | PreferredAuthentications publickey | ||
IdentityFile ~/ | IdentityFile ~/ | ||
+ | IdentitiesOnly yes | ||
</ | </ | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * '' | ||
+ | * [[https:// | ||
+ | * '' | ||
===== 접속 유지 Keep connection ===== | ===== 접속 유지 Keep connection ===== | ||
줄 71: | 줄 120: | ||
| | ||
</ | </ | ||
- | * ssh 데몬 재시작 | + | |
+ | chmod 600 ~/ | ||
+ | </ | ||
+ | | ||
+ | sudo service ssh restart | ||
+ | </ | ||
+ | |||
+ | 혹은 명령행 옵션을 직접 줘도 됨 | ||
+ | |||
+ | <code sh> | ||
+ | ssh -o ServerAliveInterval=60 hostname | ||
+ | </ | ||
===== Text 파일 Gzip 압축 전송 : 다른 서버의 파일을 현재 서버로 전송 ===== | ===== Text 파일 Gzip 압축 전송 : 다른 서버의 파일을 현재 서버로 전송 ===== | ||
줄 95: | 줄 155: | ||
===== sshpass ===== | ===== sshpass ===== | ||
* ssh, scp 등의 비밀번호를 자동으로 입력해준다.< | * ssh, scp 등의 비밀번호를 자동으로 입력해준다.< | ||
+ | # 비밀번호가 ' | ||
+ | # bash로 부터 받을 때는 export SSHPASS 명시 | ||
+ | sshpass -e ssh -o StrictHostKeyChecking=no 아이디@호스트주소 명령어 | ||
+ | |||
# 비밀번호 직접입력 | # 비밀번호 직접입력 | ||
sshpass -p비밀번호 ssh -o StrictHostKeyChecking=no 아이디@호스트주소 명령어 | sshpass -p비밀번호 ssh -o StrictHostKeyChecking=no 아이디@호스트주소 명령어 | ||
줄 109: | 줄 173: | ||
<code sh> | <code sh> | ||
ssh myhostname 'bash -s' <<' | ssh myhostname 'bash -s' <<' | ||
- | jstat -gcutil `jps | grep Bootstrap | awk ' | + | # commands... |
ENDSSH | ENDSSH | ||
</ | </ | ||
+ | |||
+ | ===== known_hosts 에 미리 호스트 추가 ===== | ||
+ | * [[http:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | <code sh> | ||
+ | ssh-keyscan -t rsa host명 >> ~/ | ||
+ | ssh-keyscan -t rsa -f host명들 이들어있는 파일명 >> ~/ | ||
+ | </ | ||
+ | |||
+ | ===== no matching cipher found. ===== | ||
+ | 아래와 같은 오류 발생시.. | ||
+ | |||
+ | >> no matching cipher found. Their offer: aes128-cbc, | ||
+ | |||
+ | 혹은 | ||
+ | >> no matching key exchange method found. Their offer: diffie-hellman-group-exchange-sha1, | ||
+ | |||
+ | |||
+ | '' | ||
+ | < | ||
+ | Ciphers aes128-cbc, | ||
+ | # 필요한 경우 | ||
+ | KexAlgorithms +diffie-hellman-group1-sha1 | ||
+ | |||
+ | # Host 를 명시해서 설정하는게 나음 | ||
+ | Host 123.123.123.123 | ||
+ | KexAlgorithms +diffie-hellman-group1-sha1 | ||
+ | </ | ||
+ | |||
+ | 혹은 명령행에 암호화 방식을 '' | ||
+ | |||
+ | <code sh> | ||
+ | ssh -c aes128-cbc kwon37xi@xxx.xx.xx.xx | ||
+ | </ | ||
+ | |||
+ | ===== SSH Pipe ===== | ||
+ | * [[https:// | ||
+ | |||
+ | ===== SSH RSA private key 를 공유해도 괜찮은가? | ||
+ | * [[https:// | ||
+ | * **강력한 비밀번호로 passphrase를 걸었다면** 괜찮지만, | ||
+ | |||
+ | |||
+ | ===== 참조 ===== | ||
+ | * [[https:// | ||