A temporary SMB/CIFS mount gives a Linux client one working path to a Windows, NAS, or Samba share without changing boot-time configuration. The mount has to prove that the client attached the intended server/share source and that the local user can read or write through the mounted directory with the expected ownership.
mount.cifs comes from the cifs-utils package and hands the share to the Linux kernel cifs filesystem driver. A root-owned credentials file keeps the password out of shell history, while uid, gid, file_mode, and dir_mode make the mounted tree appear with usable Linux ownership and permissions when the server does not provide Unix ownership metadata.
Use a manual mount for temporary access, for testing a share before adding /etc/fstab, or for proving client options during troubleshooting. Replace the sample server, share, mount point, user, UID, and GID with values from the client and SMB server, and unmount the path when the temporary access is no longer needed.
$ mount.cifs -V mount.cifs version: 7.4
Install the cifs-utils package first when this command is missing. On Debian and Ubuntu clients, use sudo apt install cifs-utils.
$ sudo install -d -m 0750 /etc/samba/credentials
$ sudo vi /etc/samba/credentials/team-share
username=alex password=replace-with-share-password domain=WORKGROUP
Omit domain= when the account is local to the server or the server does not require a workgroup or domain value. Keep the file as key=value lines with no spaces around the equals sign.
$ sudo chown root:root /etc/samba/credentials/team-share
$ sudo chmod 600 /etc/samba/credentials/team-share
$ stat -c "%a %U %G %n" /etc/samba/credentials/team-share 600 root root /etc/samba/credentials/team-share
$ sudo install -d -m 0755 /mnt/team
$ id alex uid=1001(alex) gid=1001(alex) groups=1001(alex)
The SMB server still enforces access through the account in the credentials file. The uid and gid values control how files appear to local Linux processes after the share is mounted.
$ smbclient -L //files.example.net -U alex -m SMB3 Password for [WORKGROUP\alex]: Sharename Type Comment --------- ---- ------- print$ Disk Printer Drivers team Disk IPC$ IPC IPC Service (files server) SMB1 disabled -- no workgroup available
Use the target server name and SMB account. This check confirms the share name before the kernel mount is attempted.
Related: How to browse SMB shares with smbclient
$ sudo mount -t cifs //files.example.net/team /mnt/team -o credentials=/etc/samba/credentials/team-share,uid=1001,gid=1001,file_mode=0660,dir_mode=0770
Let the client negotiate the SMB dialect unless the server requires a specific version. Add vers= only for a known compatibility requirement.
Related: How to force an SMB protocol version
$ findmnt --mountpoint /mnt/team --output TARGET,SOURCE,FSTYPE TARGET SOURCE FSTYPE /mnt/team //files.example.net/team cifs
$ ls -l /mnt/team total 4 -rw-rw---- 1 alex alex 15 Jun 16 02:29 quarterly-plan.txt
$ touch /mnt/team/manual-mount-check.txt
Use a read-only check such as ls /mnt/team instead when the share should not be written to.
$ ls -l /mnt/team/manual-mount-check.txt -rw-rw---- 1 alex alex 0 Jun 16 02:29 /mnt/team/manual-mount-check.txt
$ rm /mnt/team/manual-mount-check.txt
$ sudo umount /mnt/team