강좌
클라우드/리눅스에 관한 강좌입니다.
리눅스 분류

openssh 3.4p1 으로 버전업하기 (원격접속으로)

작성자 정보

  • 웹관리자 작성
  • 작성일

컨텐츠 정보

본문

icon01.giftitle02.gif

이번엔 openssh 3.4p1으로 버전업을 해 보겠습니다..
(원격 접속으로 모든 작업을 진행하게 된다..)

중간에 이상한 부분이나 이해가 되지 않는 부분이 있을지도 모르겠습니다..
(요즘 openssh 를 버전 별로 다 업을 하는 통에 정리를 제대로 못해서.. 궁금하신것은 게시판에 남겨주세요..)

그럼 좋은 하루 보내시기 바랍니다..

################################################################################
openssh 3.4p1 로 버전업

작성자 : 강민(linuxis@linux.co.kr)
사이트 :
http://chtla.com (초심으로)

다운 : ftp://ftp.oops.org/pub/Linux/Redhat/RPMS/7.2/openssh
http://openssh.com
에서 최신 버전(현재 3.4p1)을 다운 받는다.

###################################################
[root@chtla etc]# vi hosts.allow

ALL : 218.xx.xxx.xx <=== 추가 (이 아이피에 대해 모두 허가)
ALL : 127.0.0.1

[root@chtla etc]# vi hosts.deny

ALL : ALL <=== 추가(모두 거부)

이로써 ssh, telnet 등의 서비스가 제한된다..
(ALL : ALL 할 경우 외부에서 오는 모든 메일이 거부가 된다..)
버전업하는 동안 메일을 받아야 한다면 iptables로 막는것이 좋다. 밑부분에 iptables 로 막는 방법이 있으니
참조하기 바란다.

###################################################

[root@chtla etc]# cd xinetd.d
[root@chtla xinetd.d]# vi telnet

# default: on
# description: The telnet server serves telnet sessions; it uses # unencrypted username/password pairs for authentication.
service telnet
{
disable = no
flags = REUSE
socket_type = stream
wait = no
user = root
server = /usr/sbin/in.telnetd
log_on_failure += USERID
}

[root@chtla xinetd.d]# /etc/rc.d/init.d/xinetd restart
xinetd 를 정지함: [ 확인 ]
xinetd (을)를 시작합니다: [ 확인 ]

[root@chtla xinetd.d]# telnet localhost
Trying 127.0.0.1...
Connected to chtla.com (127.0.0.1).
Escape character is '^]'.

HancomLinux release 2.2
Kernel 2.4.13-1hl on an i686
login:

#####################################################
Root 패스워드 교체(혹시 모를 패킷 도청을 위한 것임..^^;; 너무 했나??)

[root@chtla root]# passwd
New password:
BAD PASSWORD: it is too short
Retype new password:
Sorry, passwords do not match
New password:
Retype new password:
passwd: all authentication tokens updated successfully

#####################################################
telnet 으로 접속..

위의 설정은 tcp-wrapper의 hosts.deny를 사용해 텔넷 접속을 막았지만.. 이럴게 할 경우 외부에서 오는 메일은 받을수 없게 된다..
작업하는 동안..

그래서 이번에 iptables을 이용해 텔넷을 막고 다시 openssh 을 버전업(openssh-3.4p1)을 한다..

[root@chtla root]# iptables -A INPUT -s 허가ip -d 서버 ip -p tcp -m tcp --dport 23 -j ACCEPT

[root@chtla root]# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- 211.xx.xx.xx aaa.co.kr tcp dpt:telnet

[root@chtla xinetd.d]# iptables -A INPUT -s 0/0 -d 서버ip -p tcp -m tcp --dport 23 -j DROP
<== 23 port 로 접속되는 모든 접속을 거부

[root@chtla xinetd.d]# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- 211.xx.xx.xx aaa.co.kr tcp dpt:telnet
DROP tcp -- anywhere aaa.co.kr tcp dpt:telnet

[root@chtla root]# cd /etc/xinetd.d
[root@chtla xinetd.d]# vi telnet
# default: on
# description: The telnet server serves telnet sessions; it uses # unencrypted username/password pairs for authentication.
service telnet
{
disable = no <== 변경
flags = REUSE
socket_type = stream
wait = no
user = root
server = /usr/sbin/in.telnetd
log_on_failure += USERID
}

[root@chtla xinetd.d]# /etc/rc.d/init.d/xinetd restart
xinetd 를 정지함: [ 확인 ]
xinetd (을)를 시작합니다: [ 확인 ]

이처럼 하면 특정 ip 외에 모든 접속을 거부하게 된다..
(이 경우 거부 ip를 iptable 에서 자동으로 drop 시키지는 않는다..)

서버에서 테스트시 우선 해당 서버로 가서 정지를 하게 된다..(이때 ctrl+z)으로 빠져 나온다...

8142 pts/3 T 0:00 telnet chtla.com <== ps -ax확인시
8163 pts/3 T 0:00 telnet chtla.com

해당 프로세스를 강제로 kill 해준다..

[root@chtla SOURCES]# tar xvfz openssh-3.4p1-1kr.tar.gz
[root@chtla SOURCES]# cd openssh-3.4p1-1kr
[root@chtla openssh-3.4p1-1kr]# ./configure
[root@chtla openssh-3.4p1-1kr]# make
[root@chtla openssh-3.4p1-1kr]# make install

[root@chtla etc]# pwd
/usr/local/etc
[root@chtla etc]# mkdir /etc/openssh
[root@chtla etc]# mv ssh* /etc/openssh

[root@chtla SOURCES]# cp ssh* /etc/openssh
[root@chtla SOURCES]# ln -s /usr/local/sbin/sshd /usr/sbin/sshd
[root@chtla SOURCES]# cp opensshd-inetd /etc/xinetd.d
[root@chtla xinetd.d]# mv opensshd-inetd opensshd

[root@chtla xinetd.d]# vi opensshd

# default: off
# description: OpenSSH server daemon For XINETD
service ssh
{
disable = no
flags = REUSE
protocol = tcp
socket_type = stream
instances = 50
wait = no
user = root
server = /usr/sbin/sshd <=== opensshd 로 되어 있는 것을 수정
server_args = -i
log_on_success = HOST PID
log_on_failure = HOST RECORD
}

[root@chtla xinetd.d]# /etc/rc.d/init.d/xinetd restart
xinetd 를 정지함: [ 확인 ]
xinetd (을)를 시작합니다: [ 확인 ]

================================================================

Generating public/private rsa1 key pair.
Your identification has been saved in /usr/local/etc/ssh_host_key.
Your public key has been saved in /usr/local/etc/ssh_host_key.pub.
The key fingerprint is:
ad:b6:92:b7:3f:09:ce:ff:99:5e:b7:5f:f4:9d:89:7c
root@www.chtla.com
Generating public/private dsa key pair.
Your identification has been saved in /usr/local/etc/ssh_host_dsa_key.
Your public key has been saved in /usr/local/etc/ssh_host_dsa_key.pub.
The key fingerprint is:
95:f6:19:93:0c:83:94:c4:7d:09:67:0a:17:ae:b9:48
root@www.chtla.com
Generating public/private rsa key pair.
Your identification has been saved in /usr/local/etc/ssh_host_rsa_key.
Your public key has been saved in /usr/local/etc/ssh_host_rsa_key.pub.
The key fingerprint is:
37:0f:62:5c:31:52:aa:21:a9:ec:3c:3f:64:4a:f9:39
root@www.chtla.com
id sshd || echo "WARNING: Privilege separation user "sshd" does not exist"
id: sshd: No such user
WARNING: Privilege separation user "sshd" does not exist

[root@www openssh-3.4p1]# /usr/local/sbin/sshd
Privilege separation user sshd does not exist <=== user랑 group이 없어서 그렇다..

[root@www openssh-3.4p1]# groupadd sshd
[root@www openssh-3.4p1]# useradd -g sshd sshd

[root@www openssh-3.4p1]# vi /etc/passwd

sshd:x:657:658::/home/sshd:/bin/false <===변경

[root@www openssh-3.4p1]# cd /etc/xinetd.d

[root@www xinetd.d]# vi opensshd

# default: off
# description: OpenSSH server daemon For XINETD
service ssh
{
disable = no
flags = REUSE
protocol = tcp
socket_type = stream
instances = 50
wait = no
user = root
server = /usr/local/sbin/sshd
server_args = -i
log_on_success = HOST PID
log_on_failure = HOST RECORD
}

[root@www xinetd.d]# /etc/rc.d/init.d/xinetd restart
Stopping xinetd: [ OK ]
Starting xinetd: [ OK ]

xinetd랑 같이 돌아가게 되면.. ssh로 접속한후 xinetd 를 재실행해두 접속이 끊어지지 않게 된다..

[root@www /home]# ps -ax|grep sshd
21461 ? S 0:00 sshd -i <=== 데몬이 이렇게 뜨게 된다..
21468 ? S 0:00 sshd -i

Created by KAN and MISO Return to Original Intention.. / chtla.com ( Site Version 1.0 )

관련자료

댓글 0
등록된 댓글이 없습니다.

공지사항


뉴스광장


  • 현재 회원수 :  60,017 명
  • 현재 강좌수 :  35,690 개
  • 현재 접속자 :  227 명