要在Debian上挂载CIFS共享文件夹,请按照以下步骤操作:
cifs-utils
包。如果没有,请使用以下命令安装:sudo apt update
sudo apt install cifs-utils
sudo mkdir /mnt/cifs_share
将/mnt/cifs_share
替换为您希望挂载共享文件夹的目录。
获取CIFS共享的用户名和密码。这些信息通常由网络管理员提供。请妥善保管这些凭据,因为它们将以明文形式存储在配置文件中。
编辑/etc/fstab
文件,以便在系统启动时自动挂载CIFS共享。使用文本编辑器打开/etc/fstab
文件,例如:
sudo nano /etc/fstab
/etc/fstab
文件的末尾添加以下行,用您的实际信息替换<your_username>
、<your_password>
、<server_ip_or_hostname>
和<share_path>
://server_ip_or_hostname/share_path /mnt/cifs_share cifs username=<your_username>,password=<your_password>,iocharset=utf8 0 0
例如:
//192.168.1.100/shared_folder /mnt/cifs_share cifs username=myuser,password=mypassword,iocharset=utf8 0 0
保存并关闭/etc/fstab
文件。
使用以下命令测试挂载配置是否正确:
sudo mount -a
如果没有错误消息,那么CIFS共享文件夹应该已经成功挂载到指定的目录。
注意:出于安全原因,建议使用凭据文件而不是直接在/etc/fstab
中存储用户名和密码。要使用凭据文件,请按照以下步骤操作:
/etc/cifs-credentials
:sudo nano /etc/cifs-credentials
username=<your_username>
password=<your_password>
保存并关闭凭据文件。
修改凭据文件的权限,使其仅对root用户可读:
sudo chmod 600 /etc/cifs-credentials
/etc/fstab
文件,使用凭据文件挂载CIFS共享://server_ip_or_hostname/share_path /mnt/cifs_share cifs credentials=/etc/cifs-credentials,iocharset=utf8 0 0
sudo mount -a
测试挂载配置。