>> Read No. 919 article  
tcp-wrapper와 ssh깔기

등록 2001-01-04 01:19:00     조회 6
이름 철이    

 아마 보통은 rpm을 이용하여 설치하여 쓰실 겁니다. 본 내용은 직접 컴파일하셔서
 쓰실 때 도움이 되는 내용이며, ssh 자체를 tcp-wrapper와 연동시키고자 할 경우
 참고가 될 만한 문건입니다. (배포판은 ssh와 tcp-wrapper가 무관하죠)
   내용은 모두 존칭이 생략되어 있는 점 양해해 주시고, 그럼 좋은 하루되시길
 빕니다.
 >>>>[이제부터 시작]
 * Linux에서 TCP-wrapper와 ssh를 설치하기.
 o 시작에 앞서
   아래의 문장에서
          ---[ 편집 시작 부분 ]---
                ......
           ---[ 편집 종결 부분 ]---
   로 된 부분은 실제 독자가 편집해야 할 부분을 구분지어 놓은 단락이다.
 o Tcp-wrapper 깔기
    + 소스 받아오기
    ftp://ftp.porcupine.org/pub/security 로부터 tcp-wrapper에 대한 소스
   화일을 받아온다. 일반적으로 화일명은 tcp_wrappers_x.x.tar.gz이다.
    + 컴파일
       % gunzip -c tcp_wrappers_x.x.tar.gz | tar xvf -
      % cd tcp_wrappers_x.x
       -----------------------[ 편집  시작 부분 ] ----------------------------
      % vi Makefile
        ...
        # SysV.4 Solaris 2.x OSF AIX
        REAL_DAEMON_DIR=/usr/local/sbin
        ..
         -> Makefile을 열어서 위와 같이 REAL_DAEMON_DIR이라는 부분을
        지정해 준다.
       % vi clean_exit.c
         /* 다음 부분은 Digital Unix에서 반듯이 고쳐주어야 한다. */
 #include <stdio.h>
#include <fcntl.h>         /*     <---+                          */
#include <sys/stat.h>      /*         |--  이 세 부분을 첨가     */
#include <sys/types.h>     /*     <---+                          */
         /* -----------------------------------------------------
           아래의 내용은 건너 뛰어도 상관없다. 그러나 권장.
           다음은 void clean_exit(request) 함수 선언 전에 첨가
           -----------------------------------------------------  */
 void denymsg()
{
    register int fd, nchars;
   int i;
   char tbuf[8192];
     if ((fd = open("/etc/hosts.deny-msg", O_RDONLY, 0)) < 0)
      return;
   while ((nchars = read(fd, tbuf, sizeof(tbuf))) > 0)
      (void)write(fileno(stdout), tbuf, nchars);
    (void)close(fd);
 }
       /* 또한 void clean_exit(request) 함수 안에 다음을 첨가  */
 void    clean_exit(request)
struct request_info *request;
{
....
     denymsg();                            /*  <- 이 부분을 첨가. */
    sleep(5);
    exit(0);
}
      -----------------------[ 편집  종결 부분 ] ----------------------------
       % make linux
        -> SGI와 NIS 사용자는 README를 충실히 읽어 볼 것
       
   + 인스톨
       tcp-wrapper의 Makefile에는 install 기능이 빠져 있어서 다음과 같이
      일일히 설정을 해주어야 한다.
       % su
      # install -c -o root -g root -m 755 tcpd /usr/local/sbin
      # install -c -o root -g root -m 755 safe_finger /usr/local/bin
      # install -c -o root -g root -m 755 tcpdchk     /usr/local/bin
      # install -c -o root -g root -m 755 tcpmatch    /usr/local/bin
      # install -c -o root -g root -m 755 try-from    /usr/local/bin
      # install -c -o root -g root -m 644 hosts_access.3   
                                                  /usr/local/man/man3
      # install -c -o root -g root -m 644 hosts_access.5   
                                                  /usr/local/man/man5
      # install -c -o root -g root -m 644 hosts_options.3   
                                                  /usr/local/man/man5
      # install -c -o root -g root -m 644 tcpd.8   
                                                  /usr/local/man/man8
      # install -c -o root -g root -m 644 tcpdchk.8   
                                                  /usr/local/man/man8
      # install -c -o root -g root -m 644 tcpdmatch.8   
                                                  /usr/local/man/man8
    + 설정
       우선 inetd.conf의 daemon들 중 필요한 부분을 daemon을 tcp-wrapper로 처리
      한다. (for RH 6.X)
       -----------------------[ 편집  시작 부분 ] ----------------------------
      # vi /etc/inetd.conf
...
ftp     stream  tcp     nowait  root  /usr/local/sbin/tcpd /usr/sbin/ftpd
telnet  stream  tcp     nowait  root  /usr/local/sbin/tcpd /usr/sbin/telnetd
...
      -----------------------[ 편집  종결 부분 ] ----------------------------
       만약 RH 7.0 + xinetd 사용자라면 자신이 필요한 daemon에 대해 다음과
      같이 설정한다. 아래의 예는 telnet에 대한 것이다.
      자세한 내용은 http://www.xinetd.org 를 참조하기 바란다.
       -----------------------[ 편집  시작 부분 ] ----------------------------
      # vi /etc/xinetd.d/telnet
service telnet
{
   disable  = no
   flags    = REUSE NAMEINARGS
   protocol = tcp
   socket_type = stream
   wait     = no
   user     = root
   server      = /usr/local/sbin/tcpd
   server_args = /usr/sbin/in.telnetd
   log_on_failure += USERID
}
      -----------------------[ 편집  종결 부분 ] ----------------------------
        다음은 허용되는 호스트를 등록하는 작업이다.
     
      -----------------------[ 편집  시작 부분 ] ----------------------------
      # vi /etc/hosts.deny
      ALL:ALL
       # vi /etc/hosts.allow
      ALL: LOCAL
           xxx.xxx.xxx.xxx
           ...
           yyy.yyy.emoticon/255.255.emoticon
      ....
      -----------------------[ 편집  종결 부분 ] ----------------------------
       (http://security.kaist.ac.kr/tips/tcpwrapper/TCP_Wrapper.htm 을 참조)
        만약 위의 예에서 clean_exit.c의 마지막 부분을 수정했다면 (denymsg()을
      첨가 했다면)
       다음의 화일을 만들어 준다.
       -----------------------[ 편집  시작 부분 ] ----------------------------
       # vi /etc/hosts.deny-msg
        #######################################################
          Your site is not Allowed to connect this host.
         If you want to connect from your site,
         Contact to the admistrators.
                      Admin : root at xxx.xxx.xxx        #####################################################
##        -----------------------[ 편집  종결 부분 ] ----------------------------
    + Network 재 시작
       # /etc/rc.d/init.d/inet restart     (for RH 6.X)
      # /etc/init.d/xinetd restart        (for RH 7.0)
     
    + 참고.
       일반적으로 tcp-wrapper는 시스템의 보안을 각종 daemon을 filtering을 통해
      외부로부터의 접근을 차단함으로써 강화시켜주기는 하지만 만능은 아니다.
      위의 예에서는 hosts.allow에 'ALL'이라는 항목을 두기는 했지만, 각기의
      daemon에 대해 설정해 주는 것이 좀 더 안정적이다. 특히 리눅스와 같은
      보안이 약한 시스템의 경우에 있어서는 이점을 반듯이 유의해 주어야 한다.
       다시 말하자면 ALL:로시작하는 항목을 되도록이면 놓지 말고, tcp-wrapper로
      차단시키려는 daemon name에 대해 각각 사이트를 지정해 놓는 것이 좋다.
      또한 다음에서 설명하는 ssh를 이용하면 굳이 telnet과 ftp를 사용하지
      않아도 되므로 inetd.conf에서 아예 telnetd와 ftpd를 막아 버리는 것도
      권장할 만하다.
       예)
      telnetd : LOCAL
                xxx.xxx.xxxx.xxx
      ftpd : LOCAL
                xxxx.xxx.xxx.xxx
    + 유의 사항.
      hosts.allow나 hosts.deny 작성이 '' 이후에 space나 tabe이 들어가지
      않도록 주의해야 한다.
      
o ssh깔기.
    + 소스
      www.ssh.com으로부터 받아온다. 주의할 점은 ssh-1.2.30과 ssh-2.4.0을 모두
      받아와야 한다는 점이다. (2001.1.3 현재 최신 버전은 ssh-2.4.0이다)
       또는 다음의 한국내 미러사이트에서 받아올 수 있다.
      (ftp://linux.sarang.net/mirror/network/daemon/security/ssh)        이와 함께 tcp-wrapper와 같이 연
동시키기 위해 tcp-wrapper를 만들 때       생기는 libwrap.a와 tcpd.h라는 화일을 준비한다.
 
   + ssh 컴파일
      먼저 ssh-1.2.30을 컴파일 한다.
   
      % gunzip -c ssh-1.2.30.tar.gz | tar xvf -
      % cd ssh-1.2.30
      % cp <tcp-wrapper 소스디렉토리>/libwrap.a .
      % cp <tcp-wrapper 소스디렉토리>/tcpd.h    .
      % configure --with-libwrap=`pwd` --with-etcdir=/usr/local/etc/ssh/ssh1
      % make
      # su
      # make install
       ssh-2.4.0을 컴파일 한다.
      % gunzip -c ssh-2.4.0.tar.gz | tar xvf -
      % cd ssh-2.4.0
      % cp <tcp-wrapper 소스디렉토리>/libwrap.a .
      % cp <tcp-wrapper 소스디렉토리>/tcpd.h    .
      % configure --with-libwrap=`pwd` --with-etcdir=/usr/local/etc/ssh
                                                     emoticonemoticonemoticonemoticonemoticonemoticonemoticonemoticonemoticon^
                                               이 부분이 ssh1의 설정과 다르다.
      % make
      # su
      # make install
     
      * 주의할 점은 반듯이 ssh-1.3.0을 먼저 설치한 후에 ssh-2.4.0을 설치해야
        된다.
    + 설정
       /usr/local/etc/ssh2/ssh2_config의 다음 부분을 확인해 본다.
       ------------------------[ 여기 부터 ]------------------------
## SSH1 Compatibility
 Ssh1Compatibility               yes
Ssh1AgentCompatibility          none
      ------------------------[ 여기 까지 ]------------------------
        마찬가지로 /usr/local/etc/ssh2/sshd2_config도 살펴본다.
        ------------------------[ 여기 부터 ]------------------------
 ## User restrictions
 #       AllowUsers                      "sj*,s[:isdigit:]##,s(jl|amza)"
#       DenyUsers                       skuuppa,warezdude,31373
#       DenyUsers                       don at untrusted.org #       AllowGroups                 
    staff,users #       DenyGroups                      guest
#       PermitRootLogin                 nopwd
        PermitRootLogin                 no
                                       emoticonemoticon^
                           외부에서 root login을 막는 부분이다.
## SSH1 compatibility
 #       Ssh1Compatibility               <set by configure by default>
#       Sshd1Path                       <set by configure by default>
        Ssh1Compatibility               yes
        Sshd1Path                       /usr/local/sbin/sshd1
       ------------------------[ 여기 까지 ]------------------------
        위의 설정부분 중 빠진 부분은 첨가하고, 내용이 다른 것이 있다면 수정하면
      된다.
    + sshd script만들기
       다음의 내용과 같은 script를 /etc/rc.d/init.d/sshd라는 화일로 만든다.
       ------------------------[ 여기 부터 ]------------------------
#!/bin/bash
 # Init file for OpenSSH server daemon
#
# chkconfig: 2345 55 25
# description: SSH server daemon
#
# processname: sshd
# config: /etc/ssh/ssh_host_key
# config: /etc/ssh/ssh_host_key.pub
# config: /etc/ssh/ssh_random_seed
# config: /etc/ssh/sshd_config
# pidfile: /var/run/sshd.pid
 # source function library
. /etc/rc.d/init.d/functions
 RETVAL=0
 case "$1" in
  start)
        echo -n "Starting sshd: "
        if [ ! -f /var/run/sshd.pid ] ; then
          case "`type -type success`" in
            function)
              /usr/local/sbin/sshd && success "sshd startup" || failure "sshd startup"
              RETVAL=$?
            ;;
            *)
              /usr/local/sbin/sshd && echo -n "sshd "
              RETVAL=$?
            ;;
          esac
          [ $RETVAL -eq 0 ] && touch /var/lock/subsys/sshd
        fi
        echo
        ;;
  stop)
        echo -n "Shutting down sshd: "
        if [ -f /var/run/sshd.pid ] ; then
                killproc sshd
        fi
        echo
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/sshd
        ;;
  restart)
        $0 stop
        $0 start
        RETVAL=$?
        ;;
  status)
        status sshd
        RETVAL=$?
        ;;
  *)
        echo "Usage: sshd {start|stop|restart|status}"
        exit 1
esac
 exit $RETVAL
      --------------------------[ 여기 까지 ] --------------------------
       다음의 procedure를 걸쳐서 초기 시스템의 시작시 자동으로 로딩되도록 한다.
 
      # ntsysv
        --> sshd를 선택한다.
 
      마직막으로 sshd를 시작시켜본다.
       # /etc/init.d/sshd start
     + Tcp-wrapper와의 연동
       tcp-wrapper와 연동하기 위해서 /etc/hosts.allow에 다음과 같이 daemon을
      등록시켜 주면 된다.
       --------------------------[ 여기 부터 ]--------------------------
....
sshd: LOCAL
      xxx.xxx.xxx.xx
...
      --------------------------[ 여기 까지 ]--------------------------
 --
내 서명???
이름
암호
  목록보기 윗글 아랫글
글쓰기
답장쓰기 수정 삭제
정규표현식 [ 상세 검색 ]
페이지로딩: [ 1.07 초 ] 작업시간: [ 0.37 초 ]

Copyleft 1999-2026 by JSBoard Open Project
Theme Designed by IDOO All right reserved
[TOP]

적수네 동네
+
| 적수네 동네
| 공부방
| 리눅스 잡지 서고
| LSN 소스
| 링크 모음
+---+
게시판
+
| 떠들어보세!
| 질문과 답변
| 새소식과 정보
| 1원짜리 팁?
| 대화방
+---+
칼럼?
+
| 세하 훔쳐보기
| Welcome2nite
| 혜진의 염장판
+---+
리눅스 상표권
+
| 반대 서명란
| 토론 게시판
+---+
GNU
+
| GNU 선언문
| GNU GPL
| GNU 미러 목록
+---+
프로젝트?
+
| 리눅스카운터
| RC5DES
| 실질헌법 제작
+---+
커널 소식
+
| 안정 버젼: 2.4.14
+---+
테마 선택
+
LSN 방송국?
+
| OFF AIR
+---+
회원
+
| 로그인
+---+
[ 적수네 동네 ] [ 리눅스 상표권 독점 반대 ] [ 한글 리눅스 문서 프로젝트 ] [ KrLine ] [ 사랑넷 ] [ Valid HTML 4.0! ] [ SlashDot ] [ Freshmeat ]
Copyleft (C) 1998-2001 Byeong-Chan Kim . License
TIME: 1791043031
System by WYZsoft, HDD by I.O.Linux, Mizi Research, Embryo, WOWLINUX, Domain by SarangNet, Network by KrLine.