使用EncFS在Ubuntu 16.04上加密数据

EncFS在用户空间中提供加密的文件系统。它运行没有任何特殊的权限,使用FUSE库和Linux内核模块

EncFS在用户空间中提供加密的文件系统。 它运行没有任何特殊权限,并使用FUSE库和Linux内核模块提供文件系统接口。 它是一个传递文件系统,而不是加密的块设备,这意味着它是在现有文件系统之上创建的。 本教程将介绍如何在Ubuntu 16.04(Xenial Xerus)上使用EncFS来加密数据。

1初步说明

在本教程中,我使用的是Ubuntu 16.04系统上的用户名falko 。 安全审计揭示了当前执行encfs的一些问题,请参阅下面的安全警告,以决定是否要使用encfs的方式受到这些问题的影响。 一个替代的方法是ecryptfs( https://launchpad.net/ecryptfs ),我将在另一个教程中介绍。

Encfs安全信息

“根据Taylor Hornby(Defuse Security)的安全审计,目前的Encfs实现很容易受到多种类型的攻击,例如,对加密数据进行读/写访问的攻击者可能会降低后续的解密复杂度加密数据没有被合法用户注意到,或者可能使用时序分析来推断信息。在这些问题解决之前,encres不应该被认为是敏感数据的安全之家,在这种攻击是可能的情况下。

2安装EncFS

EncFS可以安装如下(我们需要root权限,因此我们使用sudo ):

sudo apt-get -y install encfs

您现在应该看看EncFS手册页,以了解其选项:

man encfs

3使用EncFS

我现在将在我的主目录中创建加密解密的目录:

mkdir -p ~/encrypted
mkdir -p ~/decrypted

解密的目录充当加密目录的安装点。 要挂载〜/加密〜/解密 ,只需运行:

encfs ~/encrypted ~/decrypted

如果首次运行此命令,则会启动EncFS安装程序,并且必须为加密卷定义密码:

falko@server1:~$ encfs ~/encrypted ~/decrypted
Creating new encrypted volume.
Please choose from one of the following options:
enter "x" for expert configuration mode,
enter "p" for pre-configured paranoia mode,
anything else, or an empty line will select standard mode.
?> <-- p

Paranoia configuration selected.

Configuration finished. The filesystem to be created has
the following properties:
Filesystem cipher: "ssl/aes", version 3:0:2
Filename encoding: "nameio/block", version 4:0:2
Key Size: 256 bits
Block Size: 1024 bytes, including 8 byte MAC header
Each file contains 8 byte header with unique IV data.
Filenames encoded using IV chaining mode.
File data IV is chained to filename IV.
File holes passed through to ciphertext.

-------------------------- WARNING --------------------------
The external initialization-vector chaining option has been
enabled. This option disables the use of hard links on the
filesystem. Without hard links, some programs may not work.
The programs 'mutt' and 'procmail' are known to fail. For
more information, please see the encfs mailing list.
If you would like to choose another configuration setting,
please press CTRL-C now to abort and start over.

Now you will need to enter a password for your filesystem.
You will need to remember this password, as there is absolutely
no recovery mechanism. However, the password can be changed
later using encfsctl.

New Encfs Password: <-- Enter a secure password here
Verify Encfs Password: <-- Enter the secure password a second time

确保您记住密码,因为如果您忘记了密码,则无法恢复加密数据!

您现在应该在输出中找到EncFS卷

mount

falko@server1:~$ mount
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
udev on /dev type devtmpfs (rw,nosuid,relatime,size=1002996k,nr_inodes=250749,mode=755)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,noexec,relatime,size=204440k,mode=755)
/dev/mapper/server1--vg-root on / type ext4 (rw,relatime,errors=remount-ro,data=ordered)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
tmpfs on /run/lock type tmpfs (rw,nosuid,nodev,noexec,relatime,size=5120k)
tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,mode=755)
cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/lib/systemd/systemd-cgroups-agent,name=systemd,nsroot=/)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
cgroup on /sys/fs/cgroup/net_cls,net_prio type cgroup (rw,nosuid,nodev,noexec,relatime,net_cls,net_prio,nsroot=/)
cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory,nsroot=/)
cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset,nsroot=/)
cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpu,cpuacct,nsroot=/)
cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices,nsroot=/)
cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer,nsroot=/)
cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event,nsroot=/)
cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio,nsroot=/)
cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb,nsroot=/)
cgroup on /sys/fs/cgroup/pids type cgroup (rw,nosuid,nodev,noexec,relatime,pids,nsroot=/)
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=31,pgrp=1,timeout=0,minproto=5,maxproto=5,direct)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime)
mqueue on /dev/mqueue type mqueue (rw,relatime)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
fusectl on /sys/fs/fuse/connections type fusectl (rw,relatime)
/dev/sda1 on /boot type ext2 (rw,relatime,block_validity,barrier,user_xattr,acl)
tmpfs on /run/lxcfs/controllers type tmpfs (rw,relatime,size=100k,mode=700)
pids on /run/lxcfs/controllers/pids type cgroup (rw,relatime,pids,nsroot=/)
hugetlb on /run/lxcfs/controllers/hugetlb type cgroup (rw,relatime,hugetlb,nsroot=/)
blkio on /run/lxcfs/controllers/blkio type cgroup (rw,relatime,blkio,nsroot=/)
perf_event on /run/lxcfs/controllers/perf_event type cgroup (rw,relatime,perf_event,nsroot=/)
freezer on /run/lxcfs/controllers/freezer type cgroup (rw,relatime,freezer,nsroot=/)
devices on /run/lxcfs/controllers/devices type cgroup (rw,relatime,devices,nsroot=/)
cpu,cpuacct on /run/lxcfs/controllers/cpu,cpuacct type cgroup (rw,relatime,cpu,cpuacct,nsroot=/)
cpuset on /run/lxcfs/controllers/cpuset type cgroup (rw,relatime,cpuset,nsroot=/)
memory on /run/lxcfs/controllers/memory type cgroup (rw,relatime,memory,nsroot=/)
net_cls,net_prio on /run/lxcfs/controllers/net_cls,net_prio type cgroup (rw,relatime,net_cls,net_prio,nsroot=/)
name=systemd on /run/lxcfs/controllers/name=systemd type cgroup (rw,relatime,xattr,release_agent=/lib/systemd/systemd-cgroups-agent,name=systemd,nsroot=/)
lxcfs on /var/lib/lxcfs type fuse.lxcfs (rw,nosuid,nodev,relatime,user_id=0,group_id=0,allow_other)
tmpfs on /run/user/1000 type tmpfs (rw,nosuid,nodev,relatime,size=204440k,mode=700,uid=1000,gid=1000)
encfs on /home/falko/decrypted type fuse.encfs (rw,nosuid,nodev,relatime,user_id=1001,group_id=1001)
falko@server1:~$

df -h

ffalko@server1:~$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 980M 0 980M 0% /dev
tmpfs 200M 6.0M 194M 3% /run
/dev/mapper/server1--vg-root 27G 1.7G 24G 7% /
tmpfs 999M 0 999M 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 999M 0 999M 0% /sys/fs/cgroup
/dev/sda1 472M 55M 393M 13% /boot
tmpfs 200M 0 200M 0% /run/user/1000
encfs 27G 1.7G 24G 7% /home/falko/decrypted

要以加密形式保存数据,请将数据放入解密的目录中,就像使用普通目录一样:

cd ~/decrypted
echo "hello foo" > foo
echo "hello bar" > bar
ln -s foo foo2

如果您检查目录的内容,您将看到您可以以未加密的形式看到它...

ls -l

falko@server1:~/decrypted$ ls -l
total 8
-rw-rw-r-- 1 falko falko 10 Apr 26 18:54 bar
-rw-rw-r-- 1 falko falko 10 Apr 26 18:54 foo
lrwxrwxrwx 1 falko falko 3 Apr 26 18:54 foo2 -> foo

...在加密目录中,它被加密:

cd ~/encrypted
ls -l

falko@server1:~/encrypted$ ls -l
total 8
lrwxrwxrwx 1 falko falko 24 Apr 26 18:54 k2TAV0tGBWM3baIGmS62hGQa -> oFXp,s2KI6JXGzJX6Lu6,lf9
-rw-rw-r-- 1 falko falko 26 Apr 26 18:54 oFXp,s2KI6JXGzJX6Lu6,lf9
-rw-rw-r-- 1 falko falko 26 Apr 26 18:54 ZZ68NvkTaiUipHBsZGVn2ZqV
falko@server1:~/encrypted$

要卸载加密的卷,请运行:

cd
fusermount -u ~/decrypted

检查...的输出

mount

...和...

df -h

...您将看到EncFS卷不再列出。

再次安装,运行

encfs ~/encrypted ~/decrypted

将要求您提供之前定义的密码:

桌面@ server1:〜$ encfs〜/ encrypted〜/解密
EncFS密码: < - yoursecretpassword

如果您指定了正确的密码,那么将把〜/ encrypted目录安装到〜/解密的位置,从那里可以以加密形式访问加密数据。 如果您忘记密码,您的加密数据将丢失!

如果要更改密码,可以使用

encfsctl passwd ~/encrypted

命令。

falko @ server1:〜$ encfsctl passwd〜/ encrypted
输入当前的Encfs密码
EncFS密码: < - yoursecretpassword
输入新的Encfs密码
新密码密码: < - newsecretpassword
验证Encfs密码: < - newsecretpassword
卷密钥已成功更新。