Millet Porridge

English version of https://corvo.myseu.cn

0%

OpenSSH Series 3: Mount with sshfs

scp usage

I don’t use it much, just to transfer a single file.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
## Consider that I have a test.c in my local host
~ ❤ cat test.c
// #include<bits/stdc++.h>
#include <stdio.h>


int main()
{
unsigned long long x = 1ull << 31;

printf("%ld\n", x);
printf("%X\n", x);

unsigned long long y = 1ull << 32;

printf("%ld\n", y);
printf("%X\n", y);

return 0;
}

## Copy file from local host to the remote server
~ ❤ scp test.c ali:/tmp/
test.c 100% 253 5.5KB/s 00:00


## Copy file from remote server to the local host
~ ❤ scp ali:/tmp/pass.txt ./
pass.txt 100% 26 0.5KB/s 00:00

Linux mount

When I use Linux, I can mount the disk to the file system, here is the command:

1
2
3
4
5
6
7
8
9
# 1. create an empty directory for mounting
~ ❤ mkdir mnt

# 2. mount a disk partition to the directory, and you can use `ls`, `cp`, `mv` in this directory
~ ❤ mount /dev/sda3 mnt/


# 3. When we don't need to read and write disk, just umount it
~ ❤ umount /dev/sda3

When you mount the partition, you could use df -Th to get a summary of available and used disk space usage of your disk.

1
2
3
4
5
6
~ ❤  df -Th
Filesystem Type Size Used Avail Use% Mounted on
dev devtmpfs 3.8G 0 3.8G 0% /dev
run tmpfs 3.8G 1.5M 3.8G 1% /run
/dev/sda2 ext4 98G 52G 42G 56% /
/dev/sda3 ext4 77G 56G 18G 76% /home

sshfs

And there is also a tool called sshfs that allows us to mount a remote directory to the local file system.

1
sudo apt-get install sshfs

When I want to mount the /tmp directory in the remote server to local host, I can use these commands.

1
2
3
4
5
6
7
~ ❤  sshfs ali:/tmp  mnt

## check for the mount result
~ ❤ df -Th
Filesystem Type Size Used Avail Use% Mounted on
...
ali:/tmp fuse.sshfs 20G 11G 8.5G 55% /home/corvo/mnt

After the mount action, when you edit a file in local /home/corvo/mnt, just like editint it in the remote /tmp.