실습> OpenSSH 자동화 복원 스크립트 만들기
최신 버전의 OpenSSH 8.8p1 을 CentOS 7에서 삭제하고
yum 버전의 openssh 서버를 자동으로 설치하는 스크립트를 생성한다.
-- 조건 --
1. 스크립트 명 : opensshUnInstall.sh
2. 스크립트 경로 : /root/bin
3. Port 번호 : 22
-- 조건 --
Server1 ~# mkdir bin; cd bin
Server1 ~# install /dev/null opensshUnInstall.sh
Server1 ~# vi opensshUnInstall.sh
-- opensshUnInstall.sh --
#! /bin/sh
# 파일명 : opensshUnInstall.sh
# 프로그램 설명 :
# 최신 버전의 OpenSSH 8.8p1 을 CentOS 7에서 삭제하고
# yum 버전의 openssh 서버를 자동으로 설치하는 스크립트를 생성한다.
# 작성자 : 리눅스마스터넷
# 작성일 : 2021. 12. 08. (수) 20:41:18 KST
# 버전 : 2021120801
/etc/init.d/sshd stop
chkconfig --del sshd
rm -f /etc/ssh /etc/pam.d/sshd /etc/init.d/sshd
rm -rf /usr/local/openssh
yum -y install openssh openssh-server openssh-clients
#reboot
systemctl start sshd
useradd -G wheel limanet
echo 1 | passwd --stdin limanet
echo ">>> ssh 접속 테스트 <<<"
rm -rf ~/.ssh
ssh limanet@localhost
-- opensshUnInstall.sh --
# cd
# rm -rf .ssh
# useradd user1
# echo 1 | passwd --stdin user1
# ssh user1@localhost
The authenticity of host 'localhost (::1)' can't be established.
ECDSA key fingerprint is SHA256:Ppjk3gFhP3MOC6zmfvHtw95KNkb+G6p/aIXVbrEhN2A.
ECDSA key fingerprint is MD5:7a:17:65:c4:78:69:08:f9:f3:86:0c:f9:05:5e:18:17.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts.
user1@localhost's password:
Last login: Tue Dec 7 21:48:21 2021 from localhost
[user1@server1 ~]$ exit
# cat .ssh/known_hosts
localhost ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBLG2GYbfLiq+n9KgtbavqdiHIdM8TbQb0F0D6NzeZ3JktghU2BQG2ZcvwcEzKuR47zXceAFIVwKG5iBsAdnP21c=
# cd /etc/ssh
# ls
# systemctl stop sshd
# rm -f ssh_host_*
# systemctl start sshd
키가 변경되었으므로 아래와 같은 메세지가 나오면 ~/.ssh/known_hosts 파일을 삭제한다.
# ssh user1@localhost
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
SHA256:gRxrZKqDzQ0SBG0tfsnuK2kr9AgSp54zvhOpw0nkYrs.
Please contact your system administrator.
Add correct host key in /root/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /root/.ssh/known_hosts:1
ECDSA host key for localhost has changed and you have requested strict checking.
Host key verification failed.
# cd
# rm -f .ssh/known_hosts
다시 접속하면 공개키를 받아서 .ssh/known_hosts 파일에 저장한다.
# ssh user1@localhost
The authenticity of host 'localhost (::1)' can't be established.
ECDSA key fingerprint is SHA256:gRxrZKqDzQ0SBG0tfsnuK2kr9AgSp54zvhOpw0nkYrs.
ECDSA key fingerprint is MD5:b6:4f:d0:1c:bb:7f:58:25:1d:f3:b5:d0:83:08:93:07.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts.
user1@localhost's password:
Last login: Wed Dec 8 21:47:05 2021 from localhost
'Linux > SSH' 카테고리의 다른 글
| OpenSSH 자동화 스크립트 만들기 (0) | 2021.12.08 |
|---|---|
| OpenSSH 소스 삭제하기 (0) | 2021.12.08 |
| OpenSSH 소스 설치 [2] (0) | 2021.12.08 |
| OpenSSH 소스 설치 (0) | 2021.12.08 |
| ssh 에 root 접속 금지하기 (0) | 2021.12.08 |