头歌实验:Linux 网络实战(三)- Samba 服务器搭建
1 安装 Samba 服务软件
编程要求
本关任务是学会如何在线安装 Samba 软件。
具体编程要求如下:
在线安装 Samba 软件(实验环境使用的是 Ubuntu 系统)。
输入
apt-get update
apt-get install samba
2 Samba 服务器启动/关闭
编程要求
本关任务是学会如何启动/关闭 Samba 服务器。
具体编程要求如下:
开启 Samba 服务(实验环境使用的是 Ubuntu 系统)。
输入
apt-get update
apt-get install samba
sudo service smbd start
3 Samba 客户端
编程要求
本关任务是学会如何使用 smbclient 命令访问 Samba 服务器的共享资源。
注意:在执行本关任务前,首先执行如下命令来初始化任务环境。
apt-get update
apt-get install smbclient
useradd testUser
smbpasswd -a testUser(输入新设置的密码)
touch testFile
向文件 /etc/samba/smb.conf
结尾追加如下内容,并且重新启动 Samba 服务器,并且重新启动服务
[homes]
comment = smbclient homes
path = /tmp
browseable = no
writable = yes
create mask = 0664
directory mask = 0775
具体编程要求如下:
- 启动 Samba 服务;
- 使用 smbclient 命令连接本机 testUser 共享文件夹(将本机作为远程服务器,并且使用 testUser 用户去访问);
- 在远程服务器上新建一个目录 Dir;
- 将本地的一个文件(/root/testFile)上传到远程主机的 Dir 目录下并重命名为 upLoadFile。
输入
初始化环境:
apt-get update
apt-get install samba
apt-get install smbclient
useradd testUser
smbpasswd -a testUser(输入新设置的密码)
回车123456
touch testFile
vim /etc/samba/smb.conf
在行末尾,添加以下代码:
[homes]
comment = smbclient homes
path = /tmp
browseable = no
writable= yes
create mask = 0664
directory mask = 0775
重启环境:
sudo service smbd start
连接测试用户,123456 是自己设计的密码:
smbclient //127.0.0.1/testUser -U testUser%123456
使用以下命令:
smb: > mkdir Dir
smb: > put /root/testFile Dir/upLoadFile
smb: > exit
4 Samba 服务器配置
编程要求
本关任务是学会如何配置 Samba 服务器。
注意:在执行本关任务前,首先执行如下命令来初始化任务环境。
mkdir /testDir
chmod 777 /testDir
useradd testUser
smbpasswd -a testUser(输入新设置的密码)
touch testFile
具体编程要求如下:
- 自定义一个共享文件夹,将共享名字设置为 TestShare,指定共享目录为 /testDir,同时设置其可浏览,并且设置其可写属性以及创建文件和目录的默认权限分别是 0644 和 0755;
- 使用 smbclient 命令连接本机 TestShare 共享文件夹(将本机作为远程服务器,并且使用 testUser 用户去访问);
- 在远程服务器上新建一个目录 Dir;
- 将本地的一个文件(/root/testFile)上传到远程主机的 Dir 目录下并重命名为 upLoadFile。
输入
初始化环境:
apt-get install samba
apt-get install smbclient
mkdir /testDir
chmod 777 /testDir
useradd testUser
smbpasswd -a testUser(输入新设置的密码)
回车123456
touch testFile
在行末尾,添加以下代码:
vim /etc/samba/smb.conf
[TestShare]
comment = This is test share folder
path = /testDir
browseable = yes
writable= yes
create mask = 0664
directory mask = 0775
连接测试:
smbclient //127.0.0.1/TestShare -U testUser%123456
操作命令:
smb: > mkdir Dir
smb: > put /root/testFile Dir/upLoadFile
smb: > exit