2 주차 하드마운트 / 포맷 / 포맷별장단점 Vsftpd 설치 / samba 설치 / 계정권한관리 / 파일권한관리
openssh-server 설정 편하게진행하기위해서 root 계정접속가능설정 아래설정을하지않으면일반계정으로접근하여 sudo 나 su 명령을사용해야함. root@debian:~# nano /etc/ssh/sshd_config PermitRootLogin yes root@debian:~# service ssh restart
물리하드파티션정보확인 (/dev/sdx) root@debian:~# ls /dev grep sd sda sda1 sda2 sda5 root@debian:~#
/dev 에잡히는하드디스크파티션정보 하드디스크전체 sda sdb sdc sdd sde sdf 하드디스크의파티션 sda1 sda2 sda3. sdb1 sdb2 sdb3.. 씨디롬 cdrom0 cdrom1 cdrom2 파티션을생성하지않고전체를포맷할수있음 mkfs.ext4 /dev/sda ( 비추천 )
물리하드파티션정보확인 (fdisk) root@debian:~# fdisk -l Disk /dev/sda: 50 GiB, 53687091200 bytes, 104857600 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x61385b62 Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 100665343 100663296 48G 83 Linux /dev/sda2 100667390 104855551 4188162 2G 5 Extended /dev/sda5 100667392 104855551 4188160 2G 82 Linux swap / Solaris root@debian:~#
새로운하드추가 ( 버추얼박스 )
새로운하드추가 ( 버추얼박스 ) 완료
추가한하드확인 root@debian:~# ls /dev/ grep sd sda sda1 sda2 sda5 sdb root@debian:~# root@debian:~# fdisk -l Disk /dev/sda: 50 GiB, 53687091200 bytes, 104857600 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x61385b62 Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 100665343 100663296 48G 83 Linux /dev/sda2 100667390 104855551 4188162 2G 5 Extended /dev/sda5 100667392 104855551 4188160 2G 82 Linux swap / Solaris Disk /dev/sdb: 64 GiB, 68719476736 bytes, 134217728 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes root@debian:~#
하드파티션생성하기 (fdisk) root@debian:~# fdisk /dev/sdb Welcome to fdisk (util-linux 2.25.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Device does not contain a recognized partition table. Created a new DOS disklabel with disk identifier 0xad2ff97f. Command (m for help): 파티션생성 n / 파티션제거 d
전체용량을잡는파티션생성 (fdisk) Command (m for help): n // 새로만들기 Partition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions) // 파티션타입선택 Select (default p): p // primary 로선택 Partition number (1-4, default 1): 1 // 파티션넘버 1번선택 First sector (2048-134217727, default 2048): // 그냥엔터치면 2048 Last sector, +sectors or +size{k,m,g,t,p} (2048-134217727, default 134217727): // 그냥엔터치면최대치 Created a new partition 1 of type 'Linux' and of size 64 GiB. // 파티션생성됨 Command (m for help): w // 지금작업을디스크에기록하는과정 The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks.
마운트방법 (mount) ntfs : ( 파일엑세스에데몬사용 ) apt-get install ntfs-3g mount t ntfs /dev/sdb1 /media/volume1 fat : mount t fat /dev/sdb1 /media/volume1 ext4 : mount t ext4 /dev/sdb1 /media/volume1 xfs : ( 파일시스템엑세스에데몬사용 ) apt-get install xfsprogs mount t xfs /dev/sdb1 /media/volume1
파티션 EXT4 로포맷 (mkfs) root@debian:~# mkfs.ext4 /dev/sdb1 mke2fs 1.42.12 (29-Aug-2014) Creating filesystem with 16776960 4k blocks and 4194304 inodes Filesystem UUID: 3eea1c67-e8e4-4d4e-8a33-8e20a979936d Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done root@debian:~#
파티션포맷 (mkfs) ntfs : ntfs-3g 패키지필요 mkfs.ntfs /dev/sdb1 (-f 옵션으로빠른포맷가능 ) ext4 : mkfs.ext4 /dev/sdb1 xfs : mkfs.xfs /dev/sdb1
마운트하기 (mount) root@debian:~# mkdir /media/volume1 root@debian:~# mount -t ext4 /dev/sdb1 /media/volume1 root@debian:~# ls /media/volume1 lost+found root@debian:~# mount t [ 타입 ] [ 장치 ] [ 경로 ]
마운트되었는지간단히확인 root@debian:~# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 48G 696M 45G 2% / udev 10M 0 10M 0% /dev tmpfs 201M 4.4M 196M 3% /run tmpfs 501M 0 501M 0% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 501M 0 501M 0% /sys/fs/cgroup /dev/sdb1 63G 52M 60G 1% /media/volume1 root@debian:~#
파일하나써보기 root@debian:~# touch /media/volume1/test root@debian:~# ls /media/volume1/ lost+found test root@debian:~#
재부팅시에도자동마운트설정 (fstab,rc.local) root@debian:~# nano /etc/fstab /dev/sdb1 /media/volume1 ext4 defaults 0 0 ( 비추천 ) root@debian:~# nano /etc/rc.local mount -t ext4 /dev/sdb1 /media/volume1
하드가여러개? UUID 마운트 root@debian:~# blkid /dev/sda1: UUID="ce0c5108-5460-42a9-a90a-e2ee51975d29" TYPE="ext4" PARTUUID="61385b62-01" /dev/sda5: UUID="a6ed915b-04b8-46ac-8fca-21d07b1615e4" TYPE="swap" PARTUUID="61385b62-05" /dev/sdb1: UUID="3eea1c67-e8e4-4d4e-8a33-8e20a979936d" TYPE="ext4" PARTUUID="ad2ff97f-01" root@debian:~# UUID="3eea1c67-e8e4-4d4e-8a33-8e20a979936d /media/volume1 ext4 defaults 0 0
언마운트 (umount) umount /media/volume1 옵션 : -l lazy umount -f force umount
ftp 서버설치하기 ( 패키지목록갱신 ) root@debian:~# apt-get update Hit http://security.debian.org jessie/updates InRelease Ign http://httpredir.debian.org jessie InRelease Hit http://security.debian.org jessie/updates/main Sources Get:1 http://httpredir.debian.org jessie-updates InRelease [145 kb].. Hit http://httpredir.debian.org jessie/main Translation-en Fetched 158 kb in 7s (22.5 kb/s) Reading package lists... Done root@debian:~#
ftp 서버설치하기 (vsftpd) root@debian:~# apt-get install vsftpd Reading package lists... Done Building dependency tree Reading state information... Done The following extra packages will be installed: dialog openssl ssl-cert Suggested packages: ca-certificates openssl-blacklist The following NEW packages will be installed: dialog openssl ssl-cert vsftpd 0 upgraded, 4 newly installed, 0 to remove and 2 not upgraded. Need to get 1,092 kb of archives. After this operation, 3,047 kb of additional disk space will be used. Do you want to continue? [Y/n] y. root@debian:~#
서버설정하기 root@debian:~# nano /etc/vsftpd.conf write_enable=yes local_umask=0 둘중에하나 root@debian:~# service vsftpd restart root@debian:~# systemctl start vsftpd
계정추가하기 root@debian:~# adduser test Adding user `test'... Adding new group `test' (1001)... Adding new user `test' (1001) with group `test'... Creating home directory `/home/test'... Copying files from `/etc/skel'... Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully Changing the user information for test Enter the new value, or press ENTER for the default Full Name []: Room Number []: Work Phone []: Home Phone []: Other []: Is the information correct? [Y/n]
계정홈폴더지정 root@debian:~# nano /etc/passwd test:x:1001:1001:,,,:/media/volume1:/bin/bash
파일질라로접근해보기
권한문제 만든 test 파일이삭제가되지않음 폴더권한을설정해야함 root@debian:/media# ls -li total 8 786434 lrwxrwxrwx 1 root root 6 Oct 20 00:26 cdrom -> cdrom0 786435 drwxr-xr-x 2 root root 4096 Oct 20 00:26 cdrom0 2 drwxr-xr-x 3 root root 4096 Oct 30 13:07 volume1 root@debian:/media#
ls li 정보 drwxr-xr-x 3 root root rwx r-xr r-x ( 소유자 / 그룹 / 기타 ) 그리고소유자는 root, 그룹은 root test 계정은 test 그룹에속해있어서상기파일에대한액세스가불가능함
권한해결? 파일및폴더권한을 777 로수정 ( 혹은 770) 소유자를 test 로혹은 test 그룹으로설정 계정 test 를 root 그룹에넣고그룹권한을 rwx 로설정 ( 아니면그룹을생성해서그그룹에사용자추가및폴더권한수정 ) 읽기 4 / 쓰기 2 / 실행 1 읽기쓰기실행 : 7 읽기쓰기 : 6 실행만 : 1 쓰기만 : 2
test 계정을 users 그룹에추가및폴더권한수정 root@debian:/media# adduser test users Adding user `test' to group `users'... Adding user test to group users Done. root@debian:/media# chown root:users -R volume1 root@debian:/media# chmod g+rwx -R volume1 root@debian:/media#
권한정보다시확인 root@debian:/media# ls -li total 8 786434 lrwxrwxrwx 1 root root 6 Oct 20 00:26 cdrom -> cdrom0 786435 drwxr-xr-x 2 root root 4096 Oct 20 00:26 cdrom0 2 drwxrwxr-x 3 root users 4096 Oct 30 13:07 volume1 root@debian:/media#
ftp 로다시접근 ( 삭제업로드가능 )
지정된홈폴더말고상위폴더까지읽기가능 CHROOT 기능활성화
chroot 기능활성화 root@debian:/media# nano /etc/vsftpd.conf chroot_local_user=yes allow_writeable_chroot=yes root@debian:/media# service vsftpd restart
service vsftpd restart 가안될때 무슨문제인지모르겠지만 아래의방법으로 kill 하고시작한다. root@debian:~# ps -ef grep vsftpd root 1601 1 0 13:34? 00:00:00 /usr/sbin/vsftpd /etc/vsftpd.conf root 1606 1479 0 13:35 pts/1 00:00:00 grep vsftpd root@debian:~# kill 1601
다시 FTP 서버접근 상위폴더가홈폴더로고정됨 상위로올라가지못함
삼바서버설치하기 root@debian:~# apt-get install samba Reading package lists... Done Building dependency tree Reading state information... Done The following extra packages will be installed: 0 upgraded, 85 newly installed, 0 to remove and 2 not upgraded. Need to get 24.5 MB of archives. After this operation, 118 MB of additional disk space will be used. Do you want to continue? [Y/n]
삼바서버설정하기 root@debian:~# nano /etc/samba/smb.conf [volume1] comment = quipu server on VirtualBox ( 접속시알림말 ) path = /media/volume1 ( 공유할경로 ) valid users = test ( 계정 ) writable = yes ( 쓰기가능 ) directory mask = 0777 ( 디렉터리권한 ) create mask = 0777 ( 파일권한 )
삼바계정추가하기 실계정과별도 root@debian:~# smbpasswd -a test New SMB password: Retype new SMB password: Added user test. root@debian:~#
삼바서비스재시작 root@debian:~# service smbd restart root@debian:~# service nmbd restart root@debian:~#
윈도우에서삼바접근하기 \\debian \\10.0.24.31 ( 호스트이름혹은아이피주소 ) 네트워크드라이브연결
홈폴더가보인다? 아래의설정해제
디렉터리구조
권한설정 / 파일복사 / 심링크 chmod chown ln -s rm rf mkdir touch echo grep ps
유용한패키지 htop / iftop / mc
감사합니당 문의 : 카카오톡 djj9405