Operating Systems/Linux
[ Linux ] SSH 서버 설치
loopinger
2021. 7. 31. 03:16
1. CentOS7
[ SSH 서버 ]
yum install -y openssh-server
sed -i "s/^\s*PermitRootLogin.*//g" /etc/ssh/sshd_config
# root 로그인 가능하도록 설정
echo PermitRootLogin yes >> /etc/ssh/sshd_config
# 허용된 서비스 리스트 확인
firewall-cmd --list-services
# 서비스 리스트 확인
firewall-cmd --get-services
# ssh 서비스 정보 확인
firewall-cmd --info-service=ssh
systemctl restart ssh
[ 클라이언트 ]
echo Input Your SSH Server :
SSH_SERVER_IP=192.168.108.20 # read SSH_SERVER_IP
# ssh 접속 확인을 위한 패스워드 전달 매크로 설치
yum -y install expect
# ssh 클라이언트 설치
yum -y install openssh-clients
expect <<EOF
spawn ssh -oStrictHostKeyChecking=no root@${SSH_SERVER_IP} -p 22
expect "password:"
send "P@ssw0rd!\n"
expect "#"
send "ip route\n"
send "exit\n"
expect eof
EOF
2. Ubuntu20
[ SSH 서버 ]
# ssh 서버 설치
apt-get -y install openssh-server
sed -i "s/^\s*PermitRootLogin.*//g" /etc/ssh/sshd_config
# root 로그인 가능하도록 설정
echo PermitRootLogin yes >> /etc/ssh/sshd_config
systemctl restart ssh
ufw allow 22/tcp
[ 클라이언트 ]
echo Input Your SSH Server :
SSH_SERVER_IP=192.168.108.20 # read SSH_SERVER_IP
# ssh 접속 확인을 위한 패스워드 전달 매크로 설치
apt-get -y install expect
# ssh 클라이언트 설치
apt-get -y install openssh-client
expect <<EOF
spawn ssh -oStrictHostKeyChecking=no root@${SSH_SERVER_IP} -p 22
expect "password:"
send "P@ssw0rd!\n"
expect "#"
send "ip route\n"
send "exit\n"
expect eof
EOF