- Install
- Mount manually
- Credential
- Auto mount
- Other option to mount
- Execute
- Access to folders
- SSH
- Copy file
- OneDrive
Updated: 2022-11-05
This is only relevant to my personal reference at work.
The address for drive F and N is as follow:
- F: = \\fhi.no\felles
- N: = \\fhi.no\fil\styrt
- H: = \\fhi.no\home\Brukere_Y$\YOUR-USERNAME
To check the path where the folders are mounted, in Windows run command net use
in terminal with cmd
or PowerShell.
Install
Install CIFS utilities package.
sudo apt update
sudo apt install cifs-utils autofs
Mount manually
Basically you can mount the drive every time you want to access it directly with the command below but this has to be done every time you login to you machine.
sudo mkdir /mnt/F
sudo mount -t cifs -o username=YourWindowsUserName,password=YourWindowsPassword //fhi.no/Felles /mnt/F
You can run df -h
to verify that mounting windows share folder in Linux was successful.
Credential
To ensure that your username and password secure, use credential file for example /etc/cifs-credentials
with:
username=user
password=password
Then make it unreadable to others with
sudo chown root: /etc/cifs-credentials
sudo chmod 600 /etc/cifs-credentials
Then to use the credentials run:
sudo mount -t cifs -o credentials=/etc/cifs-credentials,file_mode=0777,dir_mode=0777 ://fhi.no/fil/styrt
Read more here
Auto mount
Alternatively you can automount the drive. Here I use fstad
. Edit file fstab
sudo vim /etc/fstab
Then add the following line to the file:
//fhi.no/fil/felles /mnt/F cifs credentials=/etc/cifs-credentials,file_mode=0755,dir_mode=0755 0 0
//fhi.no/fil/fil/styrt /mnt/N cifs credentials=/etc/cifs-credentials,file_mode=0755,dir_mode=0755 0 0
//fhi.no/home/brukere_Y\$//YBKA /mnt/H cifs credentials=/etc/cifs-credentials,file_mode=0755,dir_mode=0755 0 0
Then run the command to mount all the entries in /etc/fstab
sudo mount -a
To unmount any of the folder, eg. /mnt/F
. The second command is used if the
first command fails. The option -l
is equal to --lazy
. The command is
umount
and not unmount
ie. without n
in UN.
sudo umount /mnt/F
sudo umount -t cifs -l /mnt/F
This guide is copied from here.
Other option to mount
To use autofs to automount instead of fstad
. If you wonder the different
between these methods then you can read here. To start with autofs
create file
auto.cifs
in directory /etc/
F -fstype=cifs,rw,credential=/etc/cifs-credentials,uid=1000,iocharset=utf8 ://fhi.no/Felles
N -fstype=cifs,rw,credential=/etc/cifs-credentials,uid=1000,iocharset=utf8 ://fhi.no/fil/styrt
H -fstype=cifs,rw,credential=/etc/cifs-credentials,uid=1000,iocharset=utf8 ://fhi.no/home/Brukere_Y\$/MYUSERNAME
NB! Look at dealing with special symbol such as folder name ie. Brukere_Y$
which should be written
as Brukere_Y\$
. If these settings don’t work for you, try the settings below
N -fstype=cifs,rw,username=<your-username>,password=<your-password>,vers=3.0,uid=1000,file_mode=0777,dir_mode=0777,users ://fhi.no/fil/styrt
F -fstype=cifs,rw,username=<your-username>,password=<your-password>,vers=3.0,uid=1000,file_mode=0777,dir_mode=0777,users ://fhi.no/felles
To understand how mount settings is done can be referred from this website on AUTOFS. Basically the structure is
mount-point map-name options
The primary configuration file for the automounter is /etc/auto.master
, also referred to as the
master map which may be changed accordingly. Open auto.master
file and mounting directory to /mnt
.
/mnt /etc/auto.cifs
Execute
To run autofs
the execute these command in terminal:
sudo systemctl enable autofs
sudo systemctl start autofs
Other options includes restart
or stop
. To check if you have access to directory F and N run this in terminal:
cd ~ && cd /mnt/F && ls
Access to folders
Since it’s defined in the file /etc/auto.master
that mounting will be in /mnt
to access the folders is done with:
cd /mnt/N
cd /mnt/F
SSH
Install SSH to be able to access the mounted drive from other machine.
sudo apt update
sudo apt install openssh-server
If port 22 SSH in firewall not enable, then enable it by
sudo ufw allow 22
To check if SSH is running
sudo systemctl status ssh
You can actively initiate SSH if it’s not already running or stop SSH
sudo systemctl start ssh
sudo systemctl stop ssh
Copy file
To copy files to remote machine
scp FilePathWindows username@UbuntuIP:UbuntuPath
For example scp C:/Docs/MyData.csv ybk@ipAddress:/home/usr/
. Wildcard pattern
with *
could also be used. You can also read here.
OneDrive
Currently, I use this guide to mount OneDrive https://itslinuxfoss.com/install-use-onedrive-ubuntu-22-04/ but I don’t use Insync since it require admin. Previously I used this guide https://abraunegg.github.io/. The guide how to use is available here in USAGE.