Linux 学习笔记(九)

1、samba

//samba基础知识

samba主要提供了文件共享服务和名称解析

samba用到的端口:TCP:139,445 UDP:137,138

samba服务器的主要程序:smbd提供对服务器中文件资源共享访问

               nmbd提供基于NetBIOS主机名称的解析

samba的服务脚本:/etc/init.d/smb

samba的主配置文件:/etc/samba/smb.conf

修改完配置文件检查更新命令:testparm

 

在主配置文件中

  security:安全级别,share不需要身份验证,user默认,本地验证

 

linux中文件的默认权限为644,文件夹的默认权限为755

 

samba用户必须有一个同名的本地账号,密码可不相同

创建samba账号命令:pdbedit -a -u stalin

 

 pdbedit 指令功能          

-L :列出目前在数据库当中的账号与 UID 等相关信息;           

-v :需要搭配 -L 来执行,可列出更多的讯息;            

pdbedit -Lv stalin  //          

-a :新增一个可使用 Samba 的账号;          

-r :修改一个账号的相关信息;          

-x :删除一个可使用 Samba 的账号;          

-u:    指定用户名

 

smbpasswd不指定选项时可以修改指定samba账号的密码

 

[root@localhost ~]# vi /etc/samba/smb.conf

[global]    

   hosts allow = 192.168.4. 173.17.

……

[root@localhost ~]# service smb reload

重新载入 smb.conf 文件:                [确定]

//samba服务

配置samba

 1011  df -Th

 1012  umount /dev/sr0

 1013  mount /dev/sr0 /media

 1014  yum install samba

 1015  vim /etc/samba/smb.conf 

 1016  testparm

 1017  service smb start

 1018  service nmb start

 1019  netstat -ntlpu | grep mbd

 1020  service iptables status

 1021  getenforce

 1022  setenforce 0

 1023  getenforce

 1024  ifconfig

 1025  service iptables stop

 

//配置文件

    security = share

 

//最后一行

[share1]

        comment = share

        path = /share

        public = yes

        writable = yes

在运行中,\\192.168.126.154/share1

//配置文件

    security = user

//最后一行   (创建samba用户),查看现有samba用户,pdbedit

[data]

        comment = data    //描述

        path = /data      //path

        public = no       //不允许所有人访问

        valid users = stalin,roosevelt  // 可以访问的用户

        writable = no     //不可上传 

        write list = stalin  //可以上传的用户

 

在运行中,\\192.168.126.154

 

//cmd下 

net use /del /y * 断开所有连接

 

//在linux中访问 

[root@localhost ~]# smbclient -U stalin //192.168.126.154/data

Enter stalin's password:    // 123

Domain=[MYGROUP] OS=[Unix] Server=[Samba 3.5.10-114.el6]

smb: \> ls

 

[root@localhost ~]# mount -o username=stalin,password=123 //192.168.126.154/data /mnt/

[root@localhost ~]# df -Th

文件系统    类型      容量  已用  可用 已用%% 挂载点

/dev/sda3     ext4     20G  5.2G   13G  29% /

tmpfs        tmpfs   1000M  264K 1000M   1% /dev/shm

/dev/sda1     ext4    194M   28M  157M  15% /boot

/dev/mapper/vg0-lv0

              ext4     30G  172M   28G   1% /data

//192.168.126.154/data

              cifs     30G  172M   28G   1% /mnt

[root@localhost ~]# ls /mnt/

lost+found

 

 

  .                                   D        0  Mon Dec 28 11:16:23 2015

  ..                                 DR        0  Mon Dec 28 10:06:40 2015

  lost+found                          D        0  Tue Dec 22 22:01:06 2015

 

        60475 blocks of size 524288. 57060 blocks available

smb: \> get lost+found\

NT_STATUS_ACCESS_DENIED opening remote file \lost+found\

smb: \> ls

  .                                   D        0  Mon Dec 28 11:16:23 2015

  ..                                 DR        0  Mon Dec 28 10:06:40 2015

  lost+found                          D        0  Tue Dec 22 22:01:06 2015

 

        60475 blocks of size 524288. 57060 blocks available

smb: \> 

 

//创建samba用户

 1004  useradd stalin

 1005  useradd roosevelt

 1006  useradd churchill

 1007  pdbedit -a -u stalin  //创建samba用户 stalin,stalin也是系统用户

 1008  smbpasswd -a roosevelt

 1009  pdbedit -Lv

 1010  pdbedit -Lv stalin  //列出stalin的讯息

 

//永久挂载

[root@localhost stalin]# vim /etc/fstab 

UID=02f6a12f-1f47-4c22-871e-43ed23e29391 /                       ext4    defaults        1 1

UUID=4bbc74aa-49cd-4405-9017-9bb0fc894de1 /boot                   ext4    defaults        1 2

UUID=156e6307-83f3-4d9b-b897-1dca5e00f75c swap                    swap    defaults        0 0

UUID=cd17a516-8a88-4a09-a828-f429b9810576 /data                   ext4    defaults,usrquota,grpquota   0  0      

//192.168.126.154/data                  /mnt                    cifs     username=stalin,passwd=123 0 0

[root@localhost ~]# umount /mnt

[root@localhost ~]# mount -a

[root@localhost ~]# df -Th

文件系统    类型      容量  已用  可用 已用%% 挂载点

/dev/sda3     ext4     20G  5.2G   13G  29% /

tmpfs        tmpfs   1000M  264K 1000M   1% /dev/shm

/dev/sda1     ext4    194M   28M  157M  15% /boot

/dev/mapper/vg0-lv0

              ext4     30G  172M   28G   1% /data

//192.168.126.154/data

              cifs     30G  172M   28G   1% /mnt

 

2、TCP

//FTP基础知识

vsftpd 是一个基于GPL发布的FTP服务器软件。其中的vs是“ Very Secure”的缩写,由此名称缩写可以看出,本服务器的初衷就是服务的安全性。

vsftpd可同时允许匿名( anonymous )与本地用户(local)访问,还可以支持虚拟用户。

 

FTP的连接:

控制连接:TCP 21(端口号),用于发送FTP命令信息

数据连接:TCP 20(端口号),用于上传、下载数据

 

数据连接的建立类型:

主动模式:服务端从20端口主动向客户端发起连接

被动模式:服务端在指定范围内某个端口被动等待客户端连接(21号端口)

 

FTP传输模式:

文本模式:ASCII模式,以文本序列传输数据

二进制模式:Binary模式,以二进制序列传输数据

 

FTP用户的类型:

匿名用户:anonymous或ftp

本地用户:  帐号名称、密码等信息保存在passwd、shadow文件中

虚拟用户:  使用独立的帐号/密码数据文件

 

vsftpd主配置文件:/etc/vsftpd/vsftpd.conf

 

//

在windows文件下ftp://192.168.126.154

//vsftpd

//查看监听ftp的端口

[root@localhost data]# netstat -ntlpu | grep :21

 

//只能修改pub,不能修改ftp权限

[root@localhost data]# ll /var/ftp/

总用量 4

drwxr-xr-x. 2 root root 4096  3月  4 2011 pub

[root@localhost ftp]# chown ftp:ftp pub/

 

//lftp 工具

[root@localhost ftp]# yum install -y lftp

[root@localhost ~]# lftp 192.168.126.154

lftp 192.168.126.154:~> ls                            

drwxrwxrwx    3 14       50           4096 Dec 28 08:02 pub

lftp 192.168.126.154:/> cd pub/

lftp 192.168.126.154:/pub> pwd

ftp://192.168.126.154/pub

lftp 192.168.126.154:/pub> user stalin

口令: 

lftp [email protected]:~> ls

-rwxr--r--    1 4449     4450            6 Dec 28 03:26 1.txt

-rw-r--r--    1 0        0              10 Dec 28 03:30 121.txt

drwxr-xr-x    2 4449     4450         4096 Dec 28 03:29 123

 

//提取配置文件的有效信息

[root@localhost ~]# grep -v ^# /etc/vsftpd/vsftpd.conf | grep -v ^$ 

anonymous_enable=YES

anon_root=/ftproot  //匿名用户的主目录

local_enable=YES

local_root=/ftproot   //本机用户的主目录

write_enable=YES

local_umask=022

anon_umask=022

anon_upload_enable=YES

anon_mkdir_write_enable=YES

anon_other_write_enable=YES

dirmessage_enable=YES

xferlog_enable=YES

connect_from_port_20=YES

xferlog_std_format=YES

chroot_local_user=YES

listen=YES

pam_service_name=vsftpd

userlist_enable=YES

tcp_wrappers=YES

 

//匿名用户的主目录默认是/var/ftp

//本机用户的主目录默认是自己的宿主目录,例如:/home/zkpk

 

//修改完local_root=/ftproot,匿名主目录是在/var/ftp,本机目录是在/ftproot

[root@localhost ~]# lftp 192.168.126.154

lftp 192.168.126.154:~> ls

drwxrwxrwx    3 14       50           4096 Dec 28 08:02 pub

lftp [email protected]:~> user stalin

口令: 

lftp [email protected]:~> ls

drwxr-xr-x    2 4449     4450         4096 Dec 28 08:29 1

 

//匿名主目录

//anon_root=/ftproot  //匿名用户的主目录

[root@localhost ~]# chmod 777 /ftpdata/    //匿名用户的主目录是不能修改权限的

[root@localhost ~]# lftp 192.168.126.154

lftp 192.168.126.154:~> ls

ls: 登录失败: 500 OOPS: vsftpd: refusing to run with writable anonymous root

lftp 192.168.126.154:~> ls

drwxr-xr-x    2 14       50           4096 Dec 28 08:40 1

-rw-r--r--    1 0        0               5 Dec 28 08:41 1211.txt

 

//在匿名用户的主目录下,下载文件

lftp 192.168.126.154:/> get 1211.txt  //下载文件

5 bytes transferred

lftp 192.168.126.154:/> exit

[root@localhost ~]# ls

111        1211.txt  123456  456    anaconda-ks.cfg  file2        install.log.syslog  onr  test2      公共的  视频  文档  音乐

11111.txt  123       1.txt   aaaaa  etc.tar.gz       install.log  one                 st   workspace  模板    图片  下载  桌面

[root@localhost ~]# cat 1211.txt 

1211

 

//上传到匿名用户的主目录下的目录1下(不能直接上传到匿名用户的主目录)

[root@localhost ~]# lftp 192.168.126.154

lftp 192.168.126.154:~> put 11111.txt 

put: Access failed: 553 Could not create file. (11111.txt)

lftp 192.168.126.154:/> ls

drwxr-xr-x    2 14       50           4096 Dec 28 08:40 1

-rw-r--r--    1 0        0               5 Dec 28 08:41 1211.txt

lftp 192.168.126.154:/> ls

drwxr-xr-x    2 14       50           4096 Dec 28 08:40 1

-rw-r--r--    1 0        0               5 Dec 28 08:41 1211.txt

lftp 192.168.126.154:/> cd 1/                 

lftp 192.168.126.154:/1> put 11111.txt 

18 bytes transferred                        

lftp 192.168.126.154:/1> ls

-rw-r--r--    1 14       50             18 Dec 28 08:52 11111.txt

 

//本机用户的下载与上传,本机用户的主目录下是可以上传下载的

//本机主目录:/ftproot

[root@localhost ~]# lftp 192.168.126.154

lftp 192.168.126.154:~> user stalin

口令: 

lftp [email protected]:~> ls

drwxr-xr-x    2 4449     4450         4096 Dec 28 08:29 1

-rw-r--r--    1 0        0              10 Dec 28 09:04 1234555.txt

lftp [email protected]:/> get 1234555.txt 

10 bytes transferred

lftp [email protected]:/> exit

[root@localhost ~]# ls

111        123          1.txt  anaconda-ks.cfg  install.log         onr    workspace  视频  下载

11111.txt  1234555.txt  456    etc.tar.gz       install.log.syslog  st     公共的     图片  音乐

1211.txt   123456       aaaaa  file2            one                 test2  模板       文档  桌面

[root@localhost ~]# cat 1234555.txt 

123456789

[root@localhost ~]# lftp 192.168.126.154

lftp 192.168.126.154:~> user stalin

口令: 

lftp [email protected]:~> ls

drwxr-xr-x    2 4449     4450         4096 Dec 28 08:29 1

-rw-r--r--    1 0        0              10 Dec 28 09:04 1234555.txt

lftp [email protected]:/> put 1211.txt 

5 bytes transferred                             

lftp [email protected]:/> ls

drwxr-xr-x    2 4449     4450         4096 Dec 28 08:29 1

-rw-r--r--    1 4449     4450            5 Dec 28 09:05 1211.txt

-rw-r--r--    1 0        0              10 Dec 28 09:04 1234555.txt

lftp [email protected]:/> 

 

//登陆失败,密码错误

lftp 192.168.126.154:~> user stalin                    

口令: 

lftp [email protected]:~> ls

ls: 登录失败: 530 Login incorrect.  

猜你喜欢

转载自blog.csdn.net/weixin_42325841/article/details/81501447
今日推荐