2026/08/10

RPi 設定使用 camera

camera

更新套件

sudo apt update
sudo apt install ffmpeg v4l-utils libcamera-apps -y

使用一般的 web camera

用這個指令列出所有 devices,通常外接的 camera 會在 /dev/video0

v4l2-ctl --list-devices

用這個指令查詢 video0 支援的 video 格式

v4l2-ctl --device=/dev/video0 --list-formats-ext

如果有 RPi 官方提供的 camera 模組。

安裝時

  1. 找到 CSI 相機接口,將拉起連接埠的黑色或白色塑膠卡榫

  2. 有藍色膠帶的一面要朝向 HDMI/USB 埠,金屬接點面朝向 CSI 接口內部

  3. 插入排線後,將卡榫壓回固定

測試拍照

如果是用 web camera,可直接用 ffmpeg 拍照。

ffmpeg -f v4l2 -video_size 640x480 -i /dev/video0 -frames:v 1 test.jpg

如果是 RPI camera 模組,用 ffmpeg 會產生 error,要改用 rpi-cam-* 指令

rpicam-jpeg -o test.jpg

# video
rpicam-vid -t 5000 -o test.h264

將 RPi 改為 HotSpot AP

# 將 wifi 改為 hotspot AP
sudo nmcli device wifi hotspot ssid crpi4 password wifipassword ifname wlan0

# 設定可自動連線
sudo nmcli connection modify Hotspot connection.autoconnect yes

# 修改為 2.4G
sudo nmcli connection modify Hotspot 802-11-wireless.band bg

# 設定可從 wifi 轉發到 ethernet
echo "net.ipv4.ip_forward=1" | sudo tee -a /etc/sysctl.conf
sudo sysctl -p

音效卡

使用 UPTech 161 USB 音效卡測試

$ lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub
Bus 001 Device 004: ID 0d8c:0014 C-Media Electronics, Inc. Audio Adapter (Unitek Y-247A)
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub

要出現 C-Media 的那一行

$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: Headphones [bcm2835 Headphones], device 0: bcm2835 Headphones [bcm2835 Headphones]
  Subdevices: 8/8
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
  Subdevice #2: subdevice #2
  Subdevice #3: subdevice #3
  Subdevice #4: subdevice #4
  Subdevice #5: subdevice #5
  Subdevice #6: subdevice #6
  Subdevice #7: subdevice #7
card 1: vc4hdmi0 [vc4-hdmi-0], device 0: MAI PCM i2s-hifi-0 [MAI PCM i2s-hifi-0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 2: vc4hdmi1 [vc4-hdmi-1], device 0: MAI PCM i2s-hifi-0 [MAI PCM i2s-hifi-0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 3: Device [USB Audio Device], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

有出現 card 3: USB Audio

設定 USB 音效卡為預設輸出

sudo raspi-config
  • 進入 System Options -> Audio

  • 選擇你的 USB Audio Device,然後按下 Finish

調整音量

alsamixer

按下 F6 鍵,選擇你的 USB Sound Device

使用方向鍵將 SpeakerMic 的音量推高

 $ arecord -l
**** List of CAPTURE Hardware Devices ****
card 3: Device [USB Audio Device], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

card 3device 0 組合起來就是硬體代號 hw:3,0

讓系統預設就抓這張卡,我們建立一個 ALSA 設定檔

sudo nano /etc/asound.conf

defaults.ctl.card 3
defaults.pcm.card 3
defaults.timer.card 3

測試

$ aplay -D hw:3,0 /usr/share/sounds/alsa/Front_Center.wav
Playing WAVE '/usr/share/sounds/alsa/Front_Center.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Mono
aplay: set_params:1398: Channels count non available

因為這張 USB 音效卡(或是 ALSA 驅動)在處理 Mono(單聲道) 檔案時,無法直接對應到硬體的 Stereo(雙聲道) 輸出。

改為以下指令

$ aplay -D plughw:3,0 /usr/share/sounds/alsa/Front_Center.wav
Playing WAVE '/usr/share/sounds/alsa/Front_Center.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Mono

測試錄音 10秒

arecord -D plughw:3,0 -d 10 -f cd -vv test_mic.wav

設定為 0dB

amixer -c 3 sset Mic 0dB

錄影+錄音

透過 rpicam-vid 錄影後,轉發給 ffmpeg 增加錄音

  • -f segment: 自動分割

  • -segment_time 600: 每 600 秒 (10分鐘) 分割一次

  • -reset_timestamps 1: 每個片段的時間戳從 0 開始,避免播放器錯誤

  • -strftime 1: 允許檔名使用時間格式

rpicam-vid -t 0 --inline --width 1920 --height 1080 --framerate 30 \
    --bitrate 8000000 --profile high \
    --saturation 1.4 --contrast 1.2 --sharpness 1.5 --awb auto \
    -o - 2>/dev/null | \
ffmpeg -y -r 30 -i pipe:0 \
    -f alsa -i plughw:3,0 \
    -c:v copy -c:a aac -ac 1 \
    -af "volume=2.0" \
    -f segment -segment_time 300 -segment_format mp4 \
    /home/charley/Videos/test_%04d.mp4 > /dev/null 2>&1

錄影 mp4 格式,有可能會因為中途中斷而打不開檔案。改使用 ts 格式。iMovie 可讀取 mp4 及 ts 格式

rpicam-vid -t 0 --inline --width 1920 --height 1080 --framerate 30 \
    --bitrate 8000000 --profile high \
    --saturation 1.4 --contrast 1.2 --sharpness 1.5 --awb auto \
    -o - 2>/dev/null | \
ffmpeg -y -r 30 -i pipe:0 \
    -f alsa -i plughw:3,0 \
    -c:v copy -c:a aac -ac 1 \
    -af "volume=2.0" \
    -f segment -segment_time 300 -segment_format mpegts \
    /home/charley/Videos/test_%04d.ts > /dev/null 2>&1

調整畫質

AWB 模式

如果你覺得自動模式不準,可以嘗試適合的模式:

  • --awb auto: 預設自動。

  • --awb indoor: 適合一般室內燈光。

  • --awb tungsten: 適合黃光燈泡環境(這會強力補償藍色,消除黃感)。

  • --awb fluorescent: 適合辦公室日光燈環境。

或是使用 manual mode

  • --awbgains R,B: 第一個數字是紅增益,第二個是藍增益。

  • 調低第一個數 (紅)調高第二個數 (藍) 可以讓畫面變冷色調。

rpicam-jpeg --width 1920 --height 1080 --awbgains 1.2,1.8 -o test_cool.jpg

2026/08/03

pdf OCR

當遇到 pdf 複製文字是無法辨識的內容時,這是 pdf 保護文字資料的方法,可透過轉成圖片,再做 OCR 解決。

安裝軟體

# ghostscript. pdf -> 圖片
dnf install ghostscript

# 圖片
dnf install ImageMagick

# Tesseract OCR(圖片 → 文字)
sudo dnf install tesseract
tesseract --list-langs
# 預設已安裝英文
#sudo dnf install tesseract-langpack-chi-sim  # 簡體中文,視需求
#sudo dnf install tesseract-langpack-chi-tra  # 繁體中文

# 合併 pdf
dnf install poppler-utils

轉成圖片

gs -dNOPAUSE -dBATCH -sDEVICE=png16m -r300 -sOutputFile=page_%03d.png input.pdf

ocr 中文

tesseract page_001.png output_001 -l chi-tra pdf

ocr 英文

tesseract page_001.png output_001 -l eng pdf

--psdm 參數,目前測試調整後, table 換行還是有問題

--psm 常用模式:

  • 3 → 全頁自動檢測文本

  • 6 → 單塊文本

  • 11 → 密集文字或多欄

tesseract page_001.png output_001 -l eng --psm 3 pdf

多頁

for f in page_*.png; do
  base=$(basename $f .png)
  tesseract "$f" "${base}_ocr" -l eng pdf
done

合併

pdfunite page_*_ocr.pdf final_output.pdf

壓縮

gs -sDEVICE=pdfwrite -dPDFSETTINGS=/ebook -o compressed.pdf final_output.pdf

2026/07/13

rclone

rclone 等同雲端版 rsync,可以同步 / 備份資料到雲端,在不同雲端之間拷資料,把雲端 掛載成資料夾mount。支援 Google Drive、OneDrive、Dropbox、S3、Backblaze B2、FTP、SFTP、WebDAV。

ftp

rclone config

NOTICE: Config file "/root/.config/rclone/rclone.conf" not found - using defaults
No remotes found, make a new one?
n) New remote
s) Set configuration password
q) Quit config

設定過程

n/s/q> n

Enter name for new remote.
name> ftp1

Option Storage.
Type of storage to configure.
Choose a number from below, or type in your own value.
 1 / 1Fichier
   \ (fichier)
 2 / Akamai NetStorage
   \ (netstorage)
 3 / Alias for an existing remote
   \ (alias)
 4 / Amazon S3 Compliant Storage Providers including AWS, Alibaba, ArvanCloud, Ceph, ChinaMobile, Cloudflare, Cubbit, DigitalOcean, Dreamhost, Exaba, FileLu, FlashBlade, GCS, Hetzner, HuaweiOBS, IBMCOS, IDrive, Intercolo, IONOS, Leviia, Liara, Linode, LyveCloud, Magalu, Mega, Minio, Netease, Outscale, OVHcloud, Petabox, Qiniu, Rabata, RackCorp, Rclone, Scaleway, SeaweedFS, Selectel, Servercore, SpectraLogic, StackPath, Storj, Synology, TencentCOS, Wasabi, Zata, Other
   \ (s3)
 5 / Backblaze B2
   \ (b2)
 6 / Better checksums for other remotes
   \ (hasher)
 7 / Box
   \ (box)
 8 / Cache a remote
   \ (cache)
 9 / Citrix Sharefile
   \ (sharefile)
10 / Cloudinary
   \ (cloudinary)
11 / Combine several remotes into one
   \ (combine)
12 / Compress a remote
   \ (compress)
13 / DOI datasets
   \ (doi)
14 / Dropbox
   \ (dropbox)
15 / Encrypt/Decrypt a remote
   \ (crypt)
16 / Enterprise File Fabric
   \ (filefabric)
17 / FTP
   \ (ftp)
18 / FileLu Cloud Storage
   \ (filelu)
19 / Files.com
   \ (filescom)
20 / Gofile
   \ (gofile)
21 / Google Cloud Storage (this is not Google Drive)
   \ (google cloud storage)
22 / Google Drive
   \ (drive)
23 / Google Photos
   \ (google photos)
24 / HTTP
   \ (http)
25 / Hadoop distributed file system
   \ (hdfs)
26 / HiDrive
   \ (hidrive)
27 / ImageKit.io
   \ (imagekit)
28 / In memory object storage system.
   \ (memory)
29 / Internet Archive
   \ (internetarchive)
30 / Jottacloud
   \ (jottacloud)
31 / Koofr, Digi Storage and other Koofr-compatible storage providers
   \ (koofr)
32 / Linkbox
   \ (linkbox)
33 / Local Disk
   \ (local)
34 / Mail.ru Cloud
   \ (mailru)
35 / Mega
   \ (mega)
36 / Microsoft Azure Blob Storage
   \ (azureblob)
37 / Microsoft Azure Files
   \ (azurefiles)
38 / Microsoft OneDrive
   \ (onedrive)
39 / OpenDrive
   \ (opendrive)
40 / OpenStack Swift (Rackspace Cloud Files, Blomp Cloud Storage, Memset Memstore, OVH)
   \ (swift)
41 / Oracle Cloud Infrastructure Object Storage
   \ (oracleobjectstorage)
42 / Pcloud
   \ (pcloud)
43 / PikPak
   \ (pikpak)
44 / Pixeldrain Filesystem
   \ (pixeldrain)
45 / Proton Drive
   \ (protondrive)
46 / Put.io
   \ (putio)
47 / QingCloud Object Storage
   \ (qingstor)
48 / Quatrix by Maytech
   \ (quatrix)
49 / Read archives
   \ (archive)
50 / SMB / CIFS
   \ (smb)
51 / SSH/SFTP
   \ (sftp)
52 / Sia Decentralized Cloud
   \ (sia)
53 / Storj Decentralized Cloud Storage
   \ (storj)
54 / Sugarsync
   \ (sugarsync)
55 / Transparently chunk/split large files
   \ (chunker)
56 / Uloz.to
   \ (ulozto)
57 / Union merges the contents of several upstream fs
   \ (union)
58 / Uptobox
   \ (uptobox)
59 / WebDAV
   \ (webdav)
60 / Yandex Disk
   \ (yandex)
61 / Zoho
   \ (zoho)
62 / iCloud Drive
   \ (iclouddrive)
63 / premiumize.me
   \ (premiumizeme)
64 / seafile
   \ (seafile)
Storage> ftp

Option host.
FTP host to connect to.
E.g. "ftp.example.com".
Enter a value.
host> 192.168.1.3

Option user.
FTP username.
Enter a value of type string. Press Enter for the default (root).
user> maxkit

Option port.
FTP port number.
Enter a signed integer. Press Enter for the default (21).
port> 21

Option pass.
FTP password.
Choose an alternative below. Press Enter for the default (n).
y) Yes, type in my own password
g) Generate random password
n) No, leave this optional password blank (default)
y/g/n> y
Enter the password:
password:
Confirm the password:
password:

Option tls.
Use Implicit FTPS (FTP over TLS).
When using implicit FTP over TLS the client connects using TLS
right from the start which breaks compatibility with
non-TLS-aware servers. This is usually served over port 990 rather
than port 21. Cannot be used in combination with explicit FTPS.
Enter a boolean value (true or false). Press Enter for the default (false).
tls> false

Option explicit_tls.
Use Explicit FTPS (FTP over TLS).
When using explicit FTP over TLS the client explicitly requests
security from the server in order to upgrade a plain text connection
to an encrypted one. Cannot be used in combination with implicit FTPS.
Enter a boolean value (true or false). Press Enter for the default (false).
explicit_tls>

Edit advanced config?
y) Yes
n) No (default)
y/n> y

Option concurrency.
Maximum number of FTP simultaneous connections, 0 for unlimited.
Note that setting this is very likely to cause deadlocks so it should
be used with care.
If you are doing a sync or copy then make sure concurrency is one more
than the sum of `--transfers` and `--checkers`.
If you use `--check-first` then it just needs to be one more than the
maximum of `--checkers` and `--transfers`.
So for `concurrency 3` you'd use `--checkers 2 --transfers 2
--check-first` or `--checkers 1 --transfers 1`.
Enter a signed integer. Press Enter for the default (0).
concurrency> 3

Option no_check_certificate.
Do not verify the TLS certificate of the server.
Enter a boolean value (true or false). Press Enter for the default (false).
no_check_certificate>

Option disable_epsv.
Disable using EPSV even if server advertises support.
Enter a boolean value (true or false). Press Enter for the default (false).
disable_epsv>

Option disable_mlsd.
Disable using MLSD even if server advertises support.
Enter a boolean value (true or false). Press Enter for the default (false).
disable_mlsd>

Option disable_utf8.
Disable using UTF-8 even if server advertises support.
Enter a boolean value (true or false). Press Enter for the default (false).
disable_utf8>

Option writing_mdtm.
Use MDTM to set modification time (VsFtpd quirk)
Enter a boolean value (true or false). Press Enter for the default (false).
writing_mdtm>

Option force_list_hidden.
Use LIST -a to force listing of hidden files and folders. This will disable the use of MLSD.
Enter a boolean value (true or false). Press Enter for the default (false).
force_list_hidden>

Option idle_timeout.
Max time before closing idle connections.
If no connections have been returned to the connection pool in the time
given, rclone will empty the connection pool.
Set to 0 to keep connections indefinitely.
Enter a duration s,m,h,d,w,M,y. Press Enter for the default (1m0s).
idle_timeout>

Option close_timeout.
Maximum time to wait for a response to close.
Enter a duration s,m,h,d,w,M,y. Press Enter for the default (1m0s).
close_timeout>

Option tls_cache_size.
Size of TLS session cache for all control and data connections.
TLS cache allows to resume TLS sessions and reuse PSK between connections.
Increase if default size is not enough resulting in TLS resumption errors.
Enabled by default. Use 0 to disable.
Enter a signed integer. Press Enter for the default (32).
tls_cache_size>

Option disable_tls13.
Disable TLS 1.3 (workaround for FTP servers with buggy TLS)
Enter a boolean value (true or false). Press Enter for the default (false).
disable_tls13>

Option allow_insecure_tls_ciphers.
Allow insecure TLS ciphers
Setting this flag will allow the usage of the following TLS ciphers in addition to the secure defaults:
- TLS_RSA_WITH_AES_128_GCM_SHA256
Enter a boolean value (true or false). Press Enter for the default (false).
allow_insecure_tls_ciphers>

Option shut_timeout.
Maximum time to wait for data connection closing status.
Enter a duration s,m,h,d,w,M,y. Press Enter for the default (1m0s).
shut_timeout>

Option ask_password.
Allow asking for FTP password when needed.
If this is set and no password is supplied then rclone will ask for a password
Enter a boolean value (true or false). Press Enter for the default (false).
ask_password>

Option socks_proxy.
Socks 5 proxy host.

Supports the format user:pass@host:port, user@host:port, host:port.

Example:

    myUser:myPass@localhost:9005
Enter a value. Press Enter to leave empty.
socks_proxy>

Option http_proxy.
URL for HTTP CONNECT proxy
Set this to a URL for an HTTP proxy which supports the HTTP CONNECT verb.
Enter a value. Press Enter to leave empty.
http_proxy>

Option no_check_upload.
Don't check the upload is OK
Normally rclone will try to check the upload exists after it has
uploaded a file to make sure the size and modification time are as
expected.
This flag stops rclone doing these checks. This enables uploading to
folders which are write only.
You will likely need to use the --inplace flag also if uploading to
a write only folder.
Enter a boolean value (true or false). Press Enter for the default (false).
no_check_upload>

Option encoding.
The encoding for the backend.
See the [encoding section in the overview](/overview/#encoding) for more info.
Choose a number from below, or type in your own value of type Encoding.
Press Enter for the default (Slash,Del,Ctl,RightSpace,Dot).
 1 / ProFTPd can't handle '*' in file names
   \ (Asterisk,Ctl,Dot,Slash)
 2 / PureFTPd can't handle '[]' or '*' in file names
   \ (BackSlash,Ctl,Del,Dot,RightSpace,Slash,SquareBracket)
 3 / VsFTPd can't handle file names starting with dot
   \ (Ctl,LeftPeriod,Slash)
encoding>

Option description.
Description of the remote.
Enter a value. Press Enter to leave empty.
description>

Edit advanced config?
y) Yes
n) No (default)
y/n>

Configuration complete.
Options:
- type: ftp
- host: 192.168.1.3
- user: maxkit
- pass: *** ENCRYPTED ***
- concurrency: 3
Keep this "ftp1" remote?
y) Yes this is OK (default)
e) Edit this remote
d) Delete this remote
y/e/d> y

Current remotes:

Name                 Type
====                 ====
ftp1                 ftp

e) Edit existing remote
n) New remote
d) Delete remote
r) Rename remote
c) Copy remote
s) Set configuration password
q) Quit config
e/n/d/r/c/s/q> q

測試,注意 ls 會遞迴進入所有目錄 list 所有檔案

# list directory
rclone lsd ftp1:
# list file
rclone ls ftp1:

看到清單就代表連線 OK


mount 目錄

# 建立目錄
mkdir -p /mnt/ftp1

# mount --daemon 會 fork 到前景,測試時可不需要用
rclone mount ftp1: /mnt/ftp1 \
  --vfs-cache-mode full \
  --vfs-cache-max-size 5G \
  --vfs-cache-max-age 24h \
  --allow-other \
  --daemon

ls /mnt/ftp1

# unmount
fusermount3 -u /mnt/ftp1
#rclone unmount /mnt/ftp1

systemd service

vi /etc/systemd/system/rclone-ftp1.service

[Unit]
Description=Rclone FTP Mount
After=network-online.target

[Service]
Type=simple
ExecStart=/usr/bin/rclone mount ftp1: /mnt/ftp1 \
  --vfs-cache-mode full \
  --vfs-cache-max-size 5G \
  --vfs-cache-max-age 24h \
  --allow-other
ExecStop=/bin/fusermount3 -u /mnt/ftp1
Restart=always
User=root

[Install]
WantedBy=multi-user.target

啟用

systemctl daemon-reload
systemctl enable --now rclone-ftp1

sftp

設定

e/n/d/r/c/s/q> n

Enter name for new remote.
name> sftp1

Option Storage.
Type of storage to configure.
Choose a number from below, or type in your own value.
 1 / 1Fichier
   \ (fichier)
 2 / Akamai NetStorage
   \ (netstorage)
 3 / Alias for an existing remote
   \ (alias)
 4 / Amazon S3 Compliant Storage Providers including AWS, Alibaba, ArvanCloud, Ceph, ChinaMobile, Cloudflare, Cubbit, DigitalOcean, Dreamhost, Exaba, FileLu, FlashBlade, GCS, Hetzner, HuaweiOBS, IBMCOS, IDrive, Intercolo, IONOS, Leviia, Liara, Linode, LyveCloud, Magalu, Mega, Minio, Netease, Outscale, OVHcloud, Petabox, Qiniu, Rabata, RackCorp, Rclone, Scaleway, SeaweedFS, Selectel, Servercore, SpectraLogic, StackPath, Storj, Synology, TencentCOS, Wasabi, Zata, Other
   \ (s3)
 5 / Backblaze B2
   \ (b2)
 6 / Better checksums for other remotes
   \ (hasher)
 7 / Box
   \ (box)
 8 / Cache a remote
   \ (cache)
 9 / Citrix Sharefile
   \ (sharefile)
10 / Cloudinary
   \ (cloudinary)
11 / Combine several remotes into one
   \ (combine)
12 / Compress a remote
   \ (compress)
13 / DOI datasets
   \ (doi)
14 / Dropbox
   \ (dropbox)
15 / Encrypt/Decrypt a remote
   \ (crypt)
16 / Enterprise File Fabric
   \ (filefabric)
17 / FTP
   \ (ftp)
18 / FileLu Cloud Storage
   \ (filelu)
19 / Files.com
   \ (filescom)
20 / Gofile
   \ (gofile)
21 / Google Cloud Storage (this is not Google Drive)
   \ (google cloud storage)
22 / Google Drive
   \ (drive)
23 / Google Photos
   \ (google photos)
24 / HTTP
   \ (http)
25 / Hadoop distributed file system
   \ (hdfs)
26 / HiDrive
   \ (hidrive)
27 / ImageKit.io
   \ (imagekit)
28 / In memory object storage system.
   \ (memory)
29 / Internet Archive
   \ (internetarchive)
30 / Jottacloud
   \ (jottacloud)
31 / Koofr, Digi Storage and other Koofr-compatible storage providers
   \ (koofr)
32 / Linkbox
   \ (linkbox)
33 / Local Disk
   \ (local)
34 / Mail.ru Cloud
   \ (mailru)
35 / Mega
   \ (mega)
36 / Microsoft Azure Blob Storage
   \ (azureblob)
37 / Microsoft Azure Files
   \ (azurefiles)
38 / Microsoft OneDrive
   \ (onedrive)
39 / OpenDrive
   \ (opendrive)
40 / OpenStack Swift (Rackspace Cloud Files, Blomp Cloud Storage, Memset Memstore, OVH)
   \ (swift)
41 / Oracle Cloud Infrastructure Object Storage
   \ (oracleobjectstorage)
42 / Pcloud
   \ (pcloud)
43 / PikPak
   \ (pikpak)
44 / Pixeldrain Filesystem
   \ (pixeldrain)
45 / Proton Drive
   \ (protondrive)
46 / Put.io
   \ (putio)
47 / QingCloud Object Storage
   \ (qingstor)
48 / Quatrix by Maytech
   \ (quatrix)
49 / Read archives
   \ (archive)
50 / SMB / CIFS
   \ (smb)
51 / SSH/SFTP
   \ (sftp)
52 / Sia Decentralized Cloud
   \ (sia)
53 / Storj Decentralized Cloud Storage
   \ (storj)
54 / Sugarsync
   \ (sugarsync)
55 / Transparently chunk/split large files
   \ (chunker)
56 / Uloz.to
   \ (ulozto)
57 / Union merges the contents of several upstream fs
   \ (union)
58 / Uptobox
   \ (uptobox)
59 / WebDAV
   \ (webdav)
60 / Yandex Disk
   \ (yandex)
61 / Zoho
   \ (zoho)
62 / iCloud Drive
   \ (iclouddrive)
63 / premiumize.me
   \ (premiumizeme)
64 / seafile
   \ (seafile)
Storage> sftp

Option host.
SSH host to connect to.
E.g. "example.com".
Enter a value.
host> 192.168.1.3

Option user.
SSH username.
Enter a value of type string. Press Enter for the default (root).
user> maxkit

Option port.
SSH port number.
Enter a signed integer. Press Enter for the default (22).
port>

Option pass.
SSH password, leave blank to use ssh-agent.
Choose an alternative below. Press Enter for the default (n).
y) Yes, type in my own password
g) Generate random password
n) No, leave this optional password blank (default)
y/g/n> y
Enter the password:
password:
Confirm the password:
password:

Option key_pem.
Raw PEM-encoded private key.
Note that this should be on a single line with line endings replaced with '\n', eg
    key_pem = -----BEGIN RSA PRIVATE KEY-----\nMaMbaIXtE\n0gAMbMbaSsd\nMbaass\n-----END RSA PRIVATE KEY-----
This will generate the single line correctly:
    awk '{printf "%s\\n", $0}' < ~/.ssh/id_rsa
If specified, it will override the key_file parameter.
Enter a value. Press Enter to leave empty.
key_pem>

Option key_file.
Path to PEM-encoded private key file.
Leave blank or set key-use-agent to use ssh-agent.
Leading `~` will be expanded in the file name as will environment variables such as `${RCLONE_CONFIG_DIR}`.
Enter a value. Press Enter to leave empty.
key_file>

Option key_file_pass.
The passphrase to decrypt the PEM-encoded private key file.
Only PEM encrypted key files (old OpenSSH format) are supported. Encrypted keys
in the new OpenSSH format can't be used.
Choose an alternative below. Press Enter for the default (n).
y) Yes, type in my own password
g) Generate random password
n) No, leave this optional password blank (default)
y/g/n> y
Enter the password:
password:
Confirm the password:
password:

Option pubkey.
SSH public certificate for public certificate based authentication.
Set this if you have a signed certificate you want to use for authentication.
If specified will override pubkey_file.
Enter a value. Press Enter to leave empty.
pubkey>

Option pubkey_file.
Optional path to public key file.
Set this if you have a signed certificate you want to use for authentication.
Leading `~` will be expanded in the file name as will environment variables such as `${RCLONE_CONFIG_DIR}`.
Enter a value. Press Enter to leave empty.
pubkey_file>

Option key_use_agent.
When set forces the usage of the ssh-agent.
When key-file is also set, the ".pub" file of the specified key-file is read and only the associated key is
requested from the ssh-agent. This allows to avoid `Too many authentication failures for *username*` errors
when the ssh-agent contains many keys.
Enter a boolean value (true or false). Press Enter for the default (false).
key_use_agent>

Option use_insecure_cipher.
Enable the use of insecure ciphers and key exchange methods.
This enables the use of the following insecure ciphers and key exchange methods:
- aes128-cbc
- aes192-cbc
- aes256-cbc
- 3des-cbc
- diffie-hellman-group-exchange-sha256
- diffie-hellman-group-exchange-sha1
Those algorithms are insecure and may allow plaintext data to be recovered by an attacker.
This must be false if you use either ciphers or key_exchange advanced options.
Choose a number from below, or type in your own boolean value (true or false).
Press Enter for the default (false).
 1 / Use default Cipher list.
   \ (false)
 2 / Enables the use of the aes128-cbc cipher and diffie-hellman-group-exchange-sha256, diffie-hellman-group-exchange-sha1 key exchange.
   \ (true)
use_insecure_cipher>

Option disable_hashcheck.
Disable the execution of SSH commands to determine if remote file hashing is available.
Leave blank or set to false to enable hashing (recommended), set to true to disable hashing.
Enter a boolean value (true or false). Press Enter for the default (false).
disable_hashcheck>

Option ssh.
Path and arguments to external ssh binary.
Normally rclone will use its internal ssh library to connect to the
SFTP server. However it does not implement all possible ssh options so
it may be desirable to use an external ssh binary.
Rclone ignores all the internal config if you use this option and
expects you to configure the ssh binary with the user/host/port and
any other options you need.
**Important** The ssh command must log in without asking for a
password so needs to be configured with keys or certificates.
Rclone will run the command supplied either with the additional
arguments "-s sftp" to access the SFTP subsystem or with commands such
as "md5sum /path/to/file" appended to read checksums.
Any arguments with spaces in should be surrounded by "double quotes".
An example setting might be:
    ssh -o ServerAliveInterval=20 user@example.com
Note that when using an external ssh binary rclone makes a new ssh
connection for every hash it calculates.
Enter a value of type SpaceSepList. Press Enter to leave empty.
ssh>

Edit advanced config?
y) Yes
n) No (default)
y/n> n

Configuration complete.
Options:
- type: sftp
- host: 192.168.1.3
- user: maxkit
- pass: *** ENCRYPTED ***
- key_file_pass: *** ENCRYPTED ***
Keep this "sftp1" remote?
y) Yes this is OK (default)
e) Edit this remote
d) Delete this remote
y/e/d> y

Current remotes:

Name                 Type
====                 ====
ftp1                 ftp
sftp1                sftp

e) Edit existing remote
n) New remote
d) Delete remote
r) Rename remote
c) Copy remote
s) Set configuration password
q) Quit config
e/n/d/r/c/s/q> q

mount

mkdir -p /mnt/sftp1

測試

rclone lsd sftp1:

rclone mount sftp1:/ /mnt/sftp1 \
  --allow-other \
  --vfs-cache-mode full \
  --buffer-size 64M \
  --daemon

ls -al /mnt/sftp1/
/bin/fusermount3 -u /mnt/sftp1

service

vi /etc/systemd/system/rclone-sftp1.service

[Unit]
Description=Rclone SFTP Mount
After=network-online.target

[Service]
Type=simple
ExecStart=/usr/bin/rclone mount sftp1: /mnt/sftp1 \
  --vfs-cache-mode full \
  --buffer-size 64M \
  --allow-other
ExecStop=/bin/fusermount3 -u /mnt/sftp1
Restart=always
User=root

[Install]
WantedBy=multi-user.target

啟動

systemctl daemon-reload
systemctl enable --now rclone-sftp1

直接編輯設定檔

# pwd 手動用 rclone 自帶工具加密
rclone obscure "yourpassword"
# 把結果放到 pass = <OBSCURED_PASSWORD>

設定檔

~/.config/rclone/rclone.conf

[ftp1]
type = ftp
host = 192.168.1.3
user = maxkit
pass = TwE1qxopK3QB87j3QOEn9-WH0HrZhhsC
concurrency = 3

[sftp1]
type = sftp
host = 192.168.1.3
user = maxkit
pass = EhKh5h2NNeX0W0FIej8M8xoP1o5rJeER
key_file_pass = TW5-tYJMrtLeF6ys1E2wIhM5Amm8PG5K
shell_type = unix
md5sum_command = md5sum
sha1sum_command = sha1sum
chmod 600 ~/.config/rclone/rclone.conf