Linux挂载Windows共享、Linux共享

1. Linux挂载Windows共享

1.0 Samba

1.1 Windows共享文件夹

192.168.20.196Windows服务器共享ccd文件夹

1.2 Linux挂载

创建挂载目录mkdir /root/win

cifs格式挂载“源文件夹”//192.168.20.196/sharedir

使用-o添加挂载选项,指定登录Windows服务器的用户名和密码username=administrator,password=2021026

1.2.1 临时挂载(重启后无效)

mount -t cifs -o username=administrator,password=2021026 //192.168.20.196/sharedir /root/win

1.2.2 永久挂载(重启自动加载)

1) 在/etc/fstab文件中添加
//192.168.20.196/sharedir /root/win cifs username=administrator,password=2021026 0 0

2) 使用命令mount -a,加载/etc/fstab

1.3 查看与卸载

df -h查看当前服务器已经挂载的所有“设备”
使用umount /root/win卸载Windows挂载

2. Linux挂载Linux共享

2.0 NFS环境准备

Linux系统之间目录共享,使用网络文件系统NFS协议
需要在源系统Linux A和目的系统Linux B都安装nfs服务
yum -y install nfs-utils rpcbind

关闭stop并禁用disable Linux A服务器的防火墙,或者在防火墙配置nfs规则,否则无法共享目录

2.1 Linux A共享目录

2.1.1 配置/etc/exports

在192.168.0.104服务器的/etc/exports中添加要共享的目录/root/sharedir
格式如下

/root/sharedir *(rw,sync,no_root_squash)
#客户机地址 可以是 : 主机名、IP地址、网段地址、或者"、?"通配符;
#权限选项:rw表示允许读写(ro为只读)
#     sync表示同步写
#     no_root_squash表示当前客户机以root身份访问时,赋予本地root权限(默认是root_squash,将作为nfsnobody用户降权对待) (NFS 服务器共享目录用户的属性,如果用户是 root,那么对于这个共享目录来说就具有 root 的权限。)
#     给多个地址授权
/data/share 192.168.0.2(rw,sync,no_root_squash) 192.168.0.3(rw,sync,no_root_squash)
#     给某个网段内所有IP授权
/data/share 192.168.0.
(rw,sync,no_root_squash)

2.1.2 启动或重启nfs服务、rpcbind服务

启动
systemctl start rpcbindsystemctl start nfs

Linux A需要enable开机启动,否则服务器重启会导致共享失败,Linux B无法正常使用(df -h无法使用,共享目录无法使用)
systemctl enable rpcbindsystemctl enable nfs

重启
systemctl restart rpcbindsystemctl restart nfs

查看已经共享的规则showmount -e

2.2 Linux B挂载

确定已经安装nfs服务,否则将无法使用nfs协议挂载共享目录
yum -y install nfs-utils

创建挂载目录mkdir /root/linux

nfs格式挂载Linux A服务器共享的“源文件夹”192.168.0.104:/root/sharedir

2.2.1 临时挂载(重启后无效)

mount -t nfs 192.168.0.104:/root/sharedir /root/linux

2.2.2. 永久挂载(重启后自动加载)

1) 在/etc/fstab文件中添加
192.168.0.104:/root/sharedir /root/linux nfs defaults 0 0

192.168.0.104:/root/sharedir /root/linux nfs proto=tcp,vers=4.0 0 0 可以一定程度上解决远程挂载卡死的问题,(strace df -h卡在挂载的目录下)

2) 使用命令mount -a,加载/etc/fstab

2.3 查看与卸载

df -h查看当前服务器已经挂载的所有“设备”
使用umount /root/linux卸载Linux A挂载

  • 6
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 在 Linux挂载 Windows 共享目录的方法如下: 1. 在 Linux 中安装 cifs-utils 工具,可以使用如下命令: sudo apt-get install cifs-utils 2. 创建一个目录来作为挂载点,如: sudo mkdir /mnt/win_share 3. 挂载共享目录,如: sudo mount -t cifs //192.168.1.100/share /mnt/win_share -o username=user,password=pass 其中 //192.168.1.100/share 是 Windows 共享目录的地址,username 和 password 是 Windows 用户名和密码。 如需持久挂载,可以在 /etc/fstab 文件中添加如下一行 //192.168.1.100/share /mnt/win_share cifs username=user,password=pass 0 0 如果遇到权限问题,可以在 mount 命令中添加参数 -o uid=1000,gid=1000(1000为linux用户的uid和gid) 挂载成功后,在 /mnt/win_share 目录中就能访问 Windows 共享目录中的文件了。 ### 回答2: LinuxWindows是两个不同的操作系统,它们的文件系统和网络协议也是不同的,因此在Linux上访问Windows共享目录需要特定的挂载操作。 首先,确保Linux系统中samba软件已经安装,如果没有安装,需要使用以下命令安装: ``` sudo apt-get install samba ``` 然后,创建一个本地目录,用于挂载Windows共享目录。假设我们要在Linux下访问Windows共享目录“//192.168.0.100/shared”,我们可以在Linux系统上使用以下命令创建本地目录: ``` sudo mkdir /mnt/winshare ``` 接下来,编辑samba的配置文件“/etc/samba/smb.conf”,在文件的末尾添加以下内容: ``` [winshare] path = //192.168.0.100/shared valid users = username read only = yes ``` 其中,“winshare”是共享目录的名称,”//192.168.0.100/shared“是Windows共享目录的路径,”username“是这个共享目录的拥有者名称。 然后在命令行中输入以下命令以验证samba配置是否正确: ``` sudo testparm ``` 如果没有发现配置错误,就可以挂载Windows共享目录了。使用以下命令在Linux挂载Windows共享文件夹: ``` mount -t cifs //192.168.0.100/shared /mnt/winshare -o username=username,password=password ``` 其中,“username”和“password”是Windows共享目录的有效用户凭据。我们可以使用以下命令检查目录是否已挂载: ``` mount | grep winshare ``` 现在,我们就可以在Linux系统中打开“/mnt/winshare”目录来查看Windows共享文件夹中的文件了。如果想要在系统启动时自动挂载Windows共享目录,可以在“/etc/fstab”文件中添加以下行: ``` //192.168.0.100/shared /mnt/winshare cifs username=username,password=password 0 0 ``` 这样,在系统启动时,就会自动挂载Windows共享目录了。 ### 回答3: 挂载Windows共享目录是在Linux系统中使用远程共享文件的方式之一,可以使Linux系统和Windows系统之间在文件共享方面实现互通。这里介绍了使用SMB/CIFS协议进行挂载Windows共享目录的方法。 1. 首先,在Linux系统下需要安装SMB/CIFS客户端。可以通过运行以下命令来进行安装: ``` sudo apt-get update sudo apt-get install cifs-utils ``` 2. 然后,创建一个用来挂载Windows共享目录的本地文件夹,比如: ``` sudo mkdir /mnt/winshare ``` 3. 接下来,使用以下命令进行挂载: ``` sudo mount -t cifs //windowsPC/sharename /mnt/winshare -o username=windows_username,password=windows_password ``` 其中,`//windowsPC/sharename` 指定了要挂载的主机以及共享名称;`/mnt/winshare` 是指将共享目录挂载到的本地目录;`username`和`password`参数分别是Windows系统的用户名和密码。 4. 成功挂载后,可以通过执行以下命令来查看共享的内容列表: ``` ls /mnt/winshare ``` 5. 若要取消挂载,则可以执行以下命令: ``` sudo umount /mnt/winshare ``` 需要注意的是,要确保Windows系统上的共享目录是可用的,且已经设置了适当的文件共享权限。同时,可以将挂载命令添加到 `/etc/fstab` 文件中,实现开机自动挂载。 最后需要提醒的是,这种方法虽然方便实现WindowsLinux文件共享,但是在网络中传输数据时可能存在安全风险,建议仅在安全可信的网络环境下使用。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值