[Ubuntu] 07. Samba 서버 구성
카테고리: UBUNTU
🔔 공유 폴더 (익명 포함)
■ samba 설치
$ apt -y install samba
■ samba 구성
$ mkdir /home/share
$ chmod 777 /home/share
$ vi /etc/samba/smb.conf
[global]
# line 25 : add (set charset)
unix charset = UTF-8
# line 40 : uncomment and add network you allow to access
interfaces = 192.168.219.0/24
# line 101 : confirm (no authentication)
map to guest = bad user
...
[Share]
# 공유 디렉터리 지정
path = /home/share
# 쓰기 허용
writable = yes
# 게스트 사용자 허용
guest ok = yes
# 게스트 사용자로 모두 표시
guest only = yes
# 파일을 만들 때 사용 권한 [사용 권한] 설정
force create mode = 777
# 폴더를 만들 때 [사용 권한] 설정
force directory mode = 777
$ systemctl restart smbd
■ 확인
🔔 제한된 공유 폴더
$ groupadd smbgroup01
$ mkdir /home/share01
$ chgrp smbgroup01 /home/share01
$ chmod 770 /home/share01
$ vi /etc/samba/smb.conf
[global]
# line 25 : add (set charset)
unix charset = UTF-8
# line 40 : uncomment and add network you allow to access
interfaces = 192.168.219.0/24
# line 101 : comment out and add the line below
#map to guest = bad user
security = user
...
[Share01]
# 공유 디렉터리 지정
path = /home/share01
# 쓰기 허용
writable = yes
# 게스트 사용자 허용 안 함
guest ok = no
# [smbgroup01] 그룹만 허용
valid users = @smbgroup01
# 새 파일/디렉토리에 대한 그룹을 [smbgroup01]로 설정
force group = smbgroup01
# 파일 생성시 권한 설정 [770]
force create mode = 770
# 폴더 생성시 권한 설정 [770]
force directory mode = 770
# 상위 폴더에서 권한 상속
inherit permissions = yes
$ systemctl restart smbd
# add Samba user
$ smbpasswd -a test5
New SMB password: # password 설정
Retype new SMB password:
Added user test5.
$ usermod -aG smbgroup01 test5
■ 확인
🔔 Ubuntu 클라이언트
$ apt -y install smbclient cifs-utils
# [smbclient] 명령 액세스 사용
# smbclient (share name) -U (user name)
$ smbclient '\\192.168.219.195\Share01' -U test5
Password for [WORKGROUP\test5]:
Try "help" to get a list of possible commands.
smb: \> ls
. D 0 Mon Jun 5 10:59:28 2023
.. D 0 Mon Jun 5 10:48:37 2023
test.txt N 10485760 Mon Jun 5 10:59:28 2023
10218772 blocks of size 1024. 4641360 blocks available
# 파일 다운로드
smb: \> mget test.txt
Get file test.txt? y
getting file \test.txt of size 10485760 as test.txt (144225.2 KiloBytes/sec) (average 144225.4 KiloBytes/sec)
smb: \> !ls
arith.awk a.sed c.sed disk_total.awk i.sed snap test.txt
smb: \> exit
# 마운트
# [vers=(SMB protocol version)]
$ mount -t cifs -o vers=3.0,username=test5 '\\192.168.219.195\Share01' /mnt
Password for test5@\\192.168.219.195\Share01:
# 인증이 필요하지 않은 경우
$ mount -t cifs -o vers=3,username=none,password=none '\\192.168.219.195\Share' /mnt
$ df -hT
Filesystem Type Size Used Avail Use% Mounted on
tmpfs tmpfs 195M 1.2M 194M 1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv ext4 9.8G 4.9G 4.4G 53% /
tmpfs tmpfs 971M 0 971M 0% /dev/shm
tmpfs tmpfs 5.0M 0 5.0M 0% /run/lock
/dev/sda2 ext4 1.8G 130M 1.5G 8% /boot
tmpfs tmpfs 195M 4.0K 195M 1% /run/user/0
//192.168.219.195/Share01 cifs 9.8G 5.4G 4.5G 55% /mnt
//192.168.219.195/Share cifs 9.8G 5.4G 4.5G 55% /mnt
댓글 남기기