알 수 없는 사용자 2022. 10. 9. 17:52

기본 개념

보통 openssh-client 는 깔려있지만 openssh-server 는 깔려 있지 않다.

ssh를 받는 입장에서는 "openssh-server" lib 가 필요하다.

 

apt update && apt install  openssh-server sudo -y

openssh-server 를 다운받고

 

service ssh restart  이거나  service ssh start  // OK 가 뜨면 됨. 

ssh를 시작해준다.

 

ssh 서버유저네임@서버포트URL

ssh 서버유저네임@서버포트URL:포트포워딩포트


ssh finger print 없이 로그인 하는방법

1. 접속할 IP 의 키를 스캔한다.

ssh-keyscan -H 172.29.0.5

 

2. 두번 확인 하는 절차인 finger print 를 진행 X

/etc/ssh/ssh_config 에서 StrickHostKeyChecking 플래그를 no로 변경

 

 

 


비밀번호 안치고 접근하는 방법

1. sshpass 라는 lib 를 이용한다.

apt update && apt install -y sshpass

로 다운 받고

sshpass -p 비밀번호 ssh 서버유저네임@서버포트URL

 

 

ps>.

ssh server 쪽에서 root 비밀 번호를 shell 로 변경하는 방법 :

echo "root:root" | chpasswd

 

ssh server 쪽에서 root 로 로그인 허용하는 방법 :

sed -i "s|#PermitRootLogin prohibit-password|PermitRootLogin yes|" /etc/ssh/sshd_config

 


ssh 접속까지는 안하고 ssh접근후 명령어 하나만 날려주는 방법

sshpass -p 비밀번호 ssh 서버유저네임@서버포트URL shell명령어

ssh 서버유저네임@서버포트URL shell명령어

 

명령어 칠때 cd 명령어를 쓰고 싶거나 여러 명령어를 ssh로 날려주고 싶으면

shell명령어를 'bash -c "shell명령어" ' <- 이렇게 써야함.

ssh 서버유저네임@서버포트URL ' bash -c "cd /home/liam/dockerfile && pwd && docker-compose -f docker-compose.yaml up -d"'

 


shell 명령어를 치고 다음에 나올 질문에 답을 예약거는 방법

expect 라는 lib 를 씀. (확인점)