한국리눅스유저그룹 위키페이지- LUG KOREA
|
|
| Kernel News | GNOME News | KDE News | linux.kernel | comp.lang.c++ | wxWidgets GUI | comp.lang.python | |
최근 발표된 OpenSSH에서는 SFTP 사용시 Chroot를 사용할 수 있게 되었다.
Chroot는 유저가 sftp로 접속시 자신의 홈디렉토리가 최상위 루트디렉토리로(/) 인식하게 하여 다른 유저의 디렉토리나, 시스템의 루트(/) 디렉토리로 이동할 수 없도록 하는 것이다. 기존의 rpm 제공파일들은 chroot를 제공하지 않는 버전이므로, 최신 버전의 openssh source를 다운로드, 컴파일, 설치한다.
*만약 현재 운영중인 서버라면 잠시 telnet을 오픈하고 telnet으로 접속하여 작업하면 되겠다.*
텔넷 서버 패키지명은 telnet-server이며, yum telnet-server -y로 설치하면된다.
그리고 텔넷 서비스는 xinetd를 사용하므로 /etc/xinetd/telnet-server 파일에서 disable = no로 해두고 /etc/init.d/xinetd restart를 하면 텔넷 접속이 가능하다.
[root@localhost ~]# rpm -qa|grep openssh openssh-clients-4.3p2-26.el5 openssh-server-4.3p2-26.el5 openssh-4.3p2-26.el5 openssh-askpass-4.3p2-26.el5 [root@localhost ~]# rpm -e --nodeps openssh-clients openssh-server openssh openssh-askpass [root@localhost ~]# rm -rf /etc/ssh
그리고 yum 사용시 openssh 패키지는 제외하도록 설정한다.
[root@localhost ~]# vi /etc/yum.conf [main] cachedir=/var/cache/yum keepcache=0 debuglevel=2 logfile=/var/log/yum.log distroverpkg=redhat-release tolerant=1 exactarch=1 obsoletes=1 gpgcheck=1 plugins=1 # Note: yum-RHN-plugin doesn't honor this. metadata_expire=1h # Default. # installonly_limit = 3 # PUT YOUR REPOS HERE OR IN separate files named file.repo # in /etc/yum.repos.d exclude=openssh*
[root@localhost ~]# cd /usr/local/src/ [root@localhost src]# lftpget ftp:ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-5.0p1.tar.gz [root@localhost src]# tar xzf openssh-5.0p1.tar.gz </xterm> ===== 3. 소스를 컴파일 한다. =====[root@localhost src]# cd openssh-5.0p1 [root@localhost openssh-5.0p1]# pwd /usr/local/src/openssh-5.0p1 [root@localhost openssh-5.0p1]# ./configure --prefix=/usr --sysconfdir=/etc/ssh --with-pam ... OpenSSH has been configured with the following options: User binaries: /usr/bin System binaries: /usr/sbin Configuration files: /etc/ssh Askpass program: /usr/libexec/ssh-askpass Manual pages: /usr/share/man/manX PID file: /var/run Privilege separation chroot path: /var/empty sshd default user PATH: /usr/bin:/bin:/usr/sbin:/sbin Manpage format: doc PAM support: yes OSF SIA support: no KerberosV support: no SELinux support: no Smartcard support: no S/KEY support: no TCP Wrappers support: no MD5 password support: no libedit support: no Solaris process contract support: no IP address in $DISPLAY hack: no Translate v4 in v6 hack: yes BSD Auth support: no Random number source: OpenSSL internal ONLY Host: i686-pc-linux-gnu Compiler: gcc Compiler flags: -g -O2 -Wall -Wpointer-arith -Wuninitialized -Wsign-compare -Wno-pointer-sign -fstack-protector-all -std=gnu99 Preprocessor flags: Linker flags: -fstack-protector-all Libraries: -lresolv -lcrypto -lutil -lz -lnsl -lcrypt +for sshd: -lpam -ldl PAM is enabled. You may need to install a PAM control file for sshd, otherwise password authentication may fail. Example PAM control files can be found in the contrib/ subdirectory [root@localhost openssh-5.0p1]# make && make install [root@localhost openssh-5.0p1]# cp contrib/redhat/sshd.pam /etc/pam.d/sshd [root@localhost openssh-5.0p1]# cp contrib/redhat/sshd.init /etc/init.d/sshd [root@localhost openssh-5.0p1]# chmod 700 /etc/init.d/sshd [root@localhost openssh-5.0p1]# chkconfig --add sshd [root@localhost openssh-5.0p1]# chkconfig --list sshd sshd 0:해제 1:해제 2:활성 3:활성 4:활성 5:활성 6:해제 [root@localhost openssh-5.0p1]# /etc/init.d/sshd start sshd를 시작 중:WARNING: initlog is deprecated and will be removed in a future release [ OK ] [root@localhost openssh-5.0p1]# /etc/init.d/sshd stop sshd (을)를 종료 중: [ OK ]===== 4. CentOS 5.2에서는 initlog 가 deprecated되었으므로, 시작 스크립트를 아래와 같이 수정한다. =====[root@localhost openssh-5.0p1]# vim /etc/init.d/sshd ... start() { # Create keys if necessary do_rsa1_keygen do_rsa_keygen do_dsa_keygen echo -n $"Starting $prog:" #initlog -c "$SSHD $OPTIONS" && success || failure $SSHD $OPTIONS && success || failure RETVAL=$? [ "$RETVAL" = 0 ] && touch /var/lock/subsys/sshd echo } [root@localhost openssh-5.0p1]# /etc/init.d/sshd start sshd를 시작 중: [ OK ] [root@localhost openssh-5.0p1]# ssh multi@localhost The authenticity of host 'localhost (127.0.0.1)' can't be established. RSA key fingerprint is eb:6c:16:9b:2c:48:4e:90:cc:60:66:91:7d:1a:98:f2. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'localhost' (RSA) to the list of known hosts. multi@localhost's password: Last login: Sun Jul 6 04:41:28 2008 from 192.168.1.100 [multi@localhost ~]$ pwd /home/multi [multi@localhost ~]$ exit===== 5. openssh의 서버 설정파일을 수정한다. =====[root@localhost openssh-5.0p1]# ls -l /etc/ssh 합계 160 -rw-r--r-- 1 root root 125811 7월 6 04:54 moduli -rw-r--r-- 1 root root 1482 7월 6 04:54 ssh_config -rw------- 1 root root 668 7월 6 04:54 ssh_host_dsa_key -rw-r--r-- 1 root root 616 7월 6 04:54 ssh_host_dsa_key.pub -rw------- 1 root root 989 7월 6 04:54 ssh_host_key -rw-r--r-- 1 root root 653 7월 6 04:54 ssh_host_key.pub -rw------- 1 root root 1675 7월 6 04:54 ssh_host_rsa_key -rw-r--r-- 1 root root 408 7월 6 04:54 ssh_host_rsa_key.pub -rw-r--r-- 1 root root 3238 7월 6 04:54 sshd_config [root@localhost openssh-5.0p1]# vi /etc/ssh/sshd_config # override default of no subsystems #Subsystem sftp /usr/libexec/sftp-server Subsystem sftp internal-sftp # Example of overriding settings on a per-user basis Match Group sftpuser ChrootDirectory /home/%u X11Forwarding no AllowTcpForwarding no ForceCommand internal-sftp===== 6. 유저의 public_html만 업로드할 수 있도록 skel 디렉토리에 public_html 디렉토리를 만들어두면 useradd 실행시 유저의 홈디렉토리 아래에 public_html 디렉토리가 만들어지고, 퍼미션은 유저의 소유가 된다. =====[root@localhost test]# mkdir /etc/skel/public_html===== 7. 앞서 설정한 chroot를 적용할 유저의 그룹을 생성한다. =====[root@localhost openssh-5.0p1]# groupadd sftpuser===== 8. test 유저를 sftpuser 그룹으로 생성하고, 쉘접속을 하지 못하도록 /bin/false 쉘을 지정한 다음 opensshd 서비스를 시작한다. =====[root@localhost openssh-5.0p1]# useradd test -g sftpuser [root@localhost openssh-5.0p1]# usermod -s /bin/false test [root@localhost ~]# cat /etc/passwd|grep test test:x:501:503::/home/test:/bin/false [root@localhost openssh-5.0p1]# passwd test Changing password for user test. New UNIX password: Retype new UNIX password: passwd: all authentication tokens updated successfully.chroot에 의해 유저의 홈디렉토리가 인식하도록 root.root 권한을 주고, sftp 접속으로 읽을 수 있도록 퍼미션을 755로 지정한다.[root@localhost ~]# chown root.root ~test [root@localhost ~]# chmod 755 ~test [root@localhost ~]# ls -l /home|grep test drwxr-xr-x 4 root root 4096 7월 6 06:02 test [root@localhost ~]# [root@localhost openssh-5.0p1]# /etc/init.d/sshd restart sshd (을)를 종료 중: [ OK ] sshd를 시작 중: [ OK ] [root@localhost openssh-5.0p1]#===== 9. sftp로 서버에 접속해 보면 아래와 같이 자신의 홈디렉토리가 시스템의 루트디렉토리인것 처럼 보인다.(리눅스 또는 윈도우) =====[root@localhost openssh-5.0p1]# sftp test@localhost Connecting to localhost... test@localhost's password: sftp> pwd Remote working directory: / sftp> ls public_html sftp> quit [root@localhost openssh-5.0p1]# [root@localhost ~]# ssh test@localhost test@localhost's password: Could not chdir to home directory /home/test: No such file or directory [root@localhost ~]# telnet localhost Trying 127.0.0.1... Connected to localhost.localdomain (127.0.0.1). Escape character is '^]'. CentOS release 5.2 (Final) Kernel 2.6.18-92.1.6.el5 on an i686 login: test Password: Last login: Sun Jul 6 21:50:54 from localhost.localdomain Connection closed by foreign host.유저들은 sftp 클리이언트를 사용하여 자신의 홈디렉토리 아래의 public_html 디렉토리 아래에만 업로드 할 수 있다. 이제부터 ftp서버도 sftp를 사용하고, 윈도우 클리이언트는 파일질라를 사용하자. 위의 명령들에 대해 쉘스크립트를 만들어 두면 편리하겠다. http://www.openssh.org/ http://filezilla-project.org/![]()
![]()