Table of Contents

Laborator 06: Servicii de file sharing

Pentru următoarele exerciții folosim mașina virtuală GSR Debian. Mașina virtuală o gasiti la adresa de mai jos (trebuie sa va logati cu credentialele de pe cs.curs.pub.ro):

https://repository.grid.pub.ro/cs/gsr/GSR%20Debian.ova

Dupa ce o descarcati, trebuie importata în VirtualBox (File → Import Appliance).

Pentru autentificarea în mașina virtuală folosim numele de utilizator student cu parola student. Ne putem conecta și prin SSH de pe sistemul fizic folosind comanda

student@eg106-pc:~$ ssh -l student 192.168.56.115
[...]
Last login: Thu Dec  3 13:57:01 2015
student@gsr-server:~$

Contul student are permisiuni privilegiate. Putem accesa drepturile de root folosind comanda

sudo su

1. rsync

root@vm:~# apt-get update; apt-get install rsync
root@vm:~# groupadd bkpusr

root@vm:~# useradd -d /home/bkpusr -m -g bkpusr -s /bin/bash bkpusr

root@vm:~# echo "bkpusr:student" | chpasswd
root@vm:~# su - bkpusr

bkpusr@vm:~$ pwd
/home/bkpusr

bkpusr@vm:~$ mkdir stud-home
student@physical:~/Documents$ echo "1" > file1.txt

student@physical:~/Documents$ echo "2" > file2.txt

student@physical:~/Documents$ echo "3" > file3.txt
student@physical:~$ rsync -avz Documents/ bkpusr@vm.local:stud-home/
bkpusr@vm.local's password: 
sending incremental file list
./
file1.txt
file2.txt
file3.txt

sent 226 bytes  received 72 bytes  54.18 bytes/sec
total size is 6  speedup is 0.02
student@physical:~$ ssh-copy-id bkpusr@vm.local
bkpusr@vm.local's password: 
Now try logging into the machine, with "ssh 'bkpusr@vm.local'", and check in:

  ~/.ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

student@physical:~$ rsync -avz Documents/ bkpusr@vm.local:stud-home/
sending incremental file list

sent 97 bytes  received 12 bytes  218.00 bytes/sec
total size is 6  speedup is 0.06

student@physical:~$ cat sync.sh 
#!/bin/bash

RUSR=bkpusr
RHOST=vm.local
LPATH=/home/student/Documents/
RPATH=stud-home/

rsync -avz $LPATH $RUSR@$RHOST:$RPATH


root@physical:~# chown :crontab /var/spool/cron/crontabs

root@physical:~# chmod g+w /var/spool/cron/crontabs

root@physical:~# ls -ld /var/spool/cron/crontabs/
drwxrwxr-x 4 root crontab 4096 Jan 26 17:52 /var/spool/cron/crontabs/


student@physical:~$ crontab -e
crontab: installing new crontab

student@physical:~$ crontab -l | tail -n 1
* * * * * /home/student/sync.sh

root@physical:~# /etc/init.d/cron restart
Restarting periodic command scheduler: cronStopping periodic command scheduler: cron.
Starting periodic command scheduler: cron.

2. NFS

root@vm:~# apt-get install nfs-kernel-server nfs-common portmap
[...]
root@vm:~# groupadd nfsuser

root@vm:~# mkdir -p /opt/exports/home

root@vm:~# useradd -d /opt/exports/home/nfsuser -m -g nfsuser -s /bin/bash nfsuser

root@vm:~# echo "nfsuser:student" | chpasswd



root@physical:~# groupadd nfsuser

root@physical:~# useradd -d /home/nfsuser -m -g nfsuser -s /bin/bash nfsuser

root@physical:~# echo "nfsuser:student" | chpasswd



root@vm:~# apt-get install finger

root@vm:~# finger nfsuser
Login: nfsuser        			Name: 
Directory: /opt/exports/home/nfsuser	Shell: /bin/bash
Never logged in.
No mail.
No Plan.



root@physical:~# apt-get install finger

root@physical:~# finger nfsuser
Login: nfsuser        			Name: 
Directory: /home/nfsuser            	Shell: /bin/bash
Never logged in.
No mail.
No Plan.
root@vm:~# id nfsuser
uid=1002(nfsuser) gid=1003(nfsuser) groups=1003(nfsuser)



root@physical:~# id nfsuser
uid=1001(nfsuser) gid=1001(nfsuser) groups=1001(nfsuser)

root@physical:~# usermod -u 1002 nfsuser

root@physical:~# groupmod -g 1003 nfsuser

root@physical:~# id nfsuser
uid=1002(nfsuser) gid=1003(nfsuser) groups=1003(nfsuser)



root@vm:~# chown -R nfsuser:nfsuser /opt/exports
root@vm:~# tail -n 1 /etc/exports
/opt/exports/home/nfsuser 192.168.56.1(rw,insecure)
root@vm:~# exportfs -ra
exportfs: /etc/exports [1]: Neither 'subtree_check' or 'no_subtree_check' specified for export "192.168.56.1:/opt/exports/home/nfsuser".
  Assuming default behaviour ('no_subtree_check').
  NOTE: this default has changed since nfs-utils version 1.0.x

root@vm:~# exportfs
/opt/exports/home/nfsuser
		192.168.56.1
root@vm:~# /etc/init.d/rpcbind restart
Stopping rpcbind daemon....
Starting rpcbind daemon...Already running..
root@vm:~# ip a s eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000
    link/ether 00:0c:29:5a:9c:6c brd ff:ff:ff:ff:ff:ff
    inet 192.168.56.115/24 brd 192.168.48.255 scope global eth0
    inet6 fe80::20c:29ff:fe5a:9c6c/64 scope link 
       valid_lft forever preferred_lft forever



root@physical:~# apt-get install portmap

root@physical:~# apt-get install nfs-common

root@physical:~# mount 192.168.56.115:/opt/exports/home/nfsuser/ /home/nfsuser/
nfsuser@vm:~$ touch nfswrite.txt

nfsuser@vm:~$ chmod 744 nfswrite.txt 

nfsuser@vm:~$ ls -l
total 0
-rwxr--r-- 1 nfsuser nfsuser 0 Jan 26 18:34 nfswrite.txt



root@physical:~# ls -l /home/nfsuser/
total 0
-rwxr--r-- 1 nobody nogroup 0 Jan 26 18:34 nfswrite.txt
root@physical:~# umount /home/nfsuser

root@physical:~# ls -l /home/nfsuser/
total 0



nfsuser@vm:~$ ls -l
total 0
-rwxr--r-- 1 nfsuser nfsuser 0 Jan 26 18:34 nfswrite.txt
root@physical:~# mount 192.168.56.115:/opt/exports/home/nfsuser/ /home/nfsuser/

root@physical:~# ls -l /home/nfsuser/
total 0
-rwxr--r-- 1 nobody nogroup 0 Jan 26 18:34 nfswrite.txt

root@physical:~# file /home/nfsuser/nfswrite.txt 
/home/nfsuser/nfswrite.txt: empty

3. Samba

root@physical:~# apt-get install samba
[...]
root@physical:~# apt-get install smbclient smbfs
[...]

root@vm:~# apt-get install smbclient smbfs
[...]

>

S-ar putea sa fie nevoie sa porniti daemonii manual:

  • sudo service smbd start
  • sudo service nmbd start

       smbd(8)
           The smbd daemon provides the file and print services to SMB clients, such as Windows 95/98,
           Windows NT, Windows for Workgroups or LanManager. The configuration file for this daemon is
           described in smb.conf(5)

       nmbd(8)
           The nmbd daemon provides NetBIOS nameservice and browsing support. The configuration file for
           this daemon is described in smb.conf(5)

root@physical:~# netstat -tlnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      7288/rpcbind    
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1593/sshd       
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      1603/cupsd      
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1475/exim4      
tcp        0      0 0.0.0.0:445             0.0.0.0:*               LISTEN      9933/smbd       
tcp        0      0 0.0.0.0:46174           0.0.0.0:*               LISTEN      -               
tcp        0      0 0.0.0.0:36000           0.0.0.0:*               LISTEN      7794/rpc.statd  
tcp        0      0 0.0.0.0:139             0.0.0.0:*               LISTEN      9933/smbd       
tcp6       0      0 :::111                  :::*                    LISTEN      7288/rpcbind    
tcp6       0      0 :::22                   :::*                    LISTEN      1593/sshd       
tcp6       0      0 ::1:631                 :::*                    LISTEN      1603/cupsd      
tcp6       0      0 ::1:25                  :::*                    LISTEN      1475/exim4      
tcp6       0      0 :::60219                :::*                    LISTEN      7794/rpc.statd  
tcp6       0      0 :::445                  :::*                    LISTEN      9933/smbd       
tcp6       0      0 :::47114                :::*                    LISTEN      -               
tcp6       0      0 :::139                  :::*                    LISTEN      9933/smbd   
root@physical:~# grep -A 2 "workgroup =" /etc/samba/smb.conf
   workgroup = PR706
   netbios name = gsr
   
root@physical:~# /etc/init.d/samba restart
Stopping Samba daemons: nmbd smbd.
Starting Samba daemons: nmbd smbd.
Go > Network > Windows Shares > PR706 (sau numele configurat) > lista stațiilor
root@physical:~# groupadd bart

root@physical:~# useradd -d /home/bart -m -g bart -s /bin/bash bart

root@physical:~# echo "bart:student" | chpasswd

root@physical:~# /etc/init.d/samba restart
Stopping Samba daemons: nmbd smbd.
Starting Samba daemons: nmbd smbd.

student@vm:~$ smbclient -L //gsr
Enter student's password: 
session setup failed: NT_STATUS_LOGON_FAILURE

student@vm:~$ smbclient -L //gsr -U bart
Enter bart's password: 
session setup failed: NT_STATUS_LOGON_FAILURE
root@physical:~# smbpasswd -a bart
New SMB password:
Retype new SMB password:
Added user bart.


student@vm:~$ smbclient -L //gsr -U bart
Enter bart's password: 
Domain=[PR706] OS=[Unix] Server=[Samba 3.6.1]

	Sharename       Type      Comment
	---------       ----      -------
	print$          Disk      Printer Drivers
	IPC$            IPC       IPC Service (physical server)
	bart            Disk      Home Directories


Domain=[PR706] OS=[Unix] Server=[Samba 3.6.1]

	Server               Comment
	---------            -------
	GSR                  physical server

	Workgroup            Master
	---------            -------
	PR706                GSR
root@physical:~# su - bart

bart@physical:~$ pwd
/home/bart

bart@physical:~$ mkdir private

bart@physical:~$ chmod 744 private/

root@physical:~# tail -n 6 /etc/samba/smb.conf
[bart_is_sharing]
        comment = bart's shared folder
        read only = no
        path = /home/bart/private
        guest ok = no
        valid users = bart

root@physical:~# /etc/init.d/samba restart
Stopping Samba daemons: nmbd smbd.
Starting Samba daemons: nmbd smbd.

student@vm:~$ smbclient -L //gsr/ -U bart
Enter bart's password: 
Domain=[PR706] OS=[Unix] Server=[Samba 3.6.1]

	Sharename       Type      Comment
	---------       ----      -------
	print$          Disk      Printer Drivers
	bart_is_sharing Disk      bart's shared folder
	IPC$            IPC       IPC Service (physical server)
	bart            Disk      Home Directories
Domain=[PR706] OS=[Unix] Server=[Samba 3.6.1]

	Server               Comment
	---------            -------
	GSR                  physical server

	Workgroup            Master
	---------            -------
	PR706                GSR


student@vm:~$ echo "text" > file.txt

student@vm:~$ smbclient //gsr/bart_is_sharing -U bart
Enter bart's password: 
Domain=[PR706] OS=[Unix] Server=[Samba 3.6.1]
smb: \> ?
?              allinfo        altname        archive        blocksize      
cancel         case_sensitive cd             chmod          chown          
close          del            dir            du             echo           
exit           get            getfacl        geteas         hardlink       
help           history        iosize         lcd            link           
lock           lowercase      ls             l              mask           
md             mget           mkdir          more           mput           
newer          open           posix          posix_encrypt  posix_open     
posix_mkdir    posix_rmdir    posix_unlink   print          prompt         
put            pwd            q              queue          quit           
readlink       rd             recurse        reget          rename         
reput          rm             rmdir          showacls       setea          
setmode        stat           symlink        tar            tarmode        
translate      unlock         volume         vuid           wdel           
logon          listconnect    showconnect    ..             !              
smb: \> ls
  .                                   D        0  Thu Jan 26 21:16:37 2012
  ..                                  D        0  Thu Jan 26 21:17:44 2012
		40317 blocks of size 2097152. 37508 blocks available

smb: \> put file.txt
putting file file.txt as \file.txt (0.3 kb/s) (average 0.3 kb/s)

smb: \> ls 
  .                                   D        0  Thu Jan 26 21:30:24 2012
  ..                                  D        0  Thu Jan 26 21:17:44 2012
  file.txt                            A        5  Thu Jan 26 21:30:24 2012

smb: \> exit

student@vm:~$ 

4. Bonus