1. 安装cifs-utils

sudo apt-get install cifs-utils

2. 查看远程目录

shylock@ubuntu:~$ smbclient -L 10.10.10.10 -U test%password

        Sharename       Type      Comment
        ---------       ----      -------
        project         Disk      
        IPC$            IPC       IPC Service (Samba Server Version 4.3.11-Ubuntu)
        test           Disk      Home Directories
SMB1 disabled -- no workgroup available

3. 挂载远程目录

shylock@ubuntu:/mnt/test$ sudo mount.cifs //10.10.10.10/test /home/shylock/test -o username='test',password='password',vers=1.0

:默认mount.cifs挂载的是smb3,如果要挂载smb1,要加上,vers=1.0

4.开机自动挂载

  • 写一个可执行脚本smbinit ,内容如下:
#!/bin/sh
sudo mount.cifs //10.10.10.10/test /home/shylock/test -o username='test',password='password',vers=1.0
  • 赋予x权限
shylock@ubuntu:~$ sudo chmod +x /etc/init.d/smbinit 
  • 在rc.local中加入echo "1234" | sudo -S "/etc/init.d/smbinit",如下:
shylock@ubuntu:~$ cat /etc/rc.local                                   
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
echo "1234" | sudo -S "/etc/init.d/smbinit"
exit 0
shylock@ubuntu:~$ 

注:

  • rc.local是一个启动时自动执行的脚本,如果没有自动执行,检查一下是否有x权限
  • "1234"是root用户的密码,该语句表示用sudo执行脚本

5. 本文引用

封面图片:PS自己做的
教程参考:多篇参考,未记录来源