Showing posts with label vi. Show all posts
Showing posts with label vi. Show all posts

Thursday, December 29, 2011

[Linux/Mac]给一个文件/目录加密

如果你像我一样越来越依赖类似Dropbox这样的云端存储工具来同步几台不同的机器上的数据,同时又担心放上去了重要的文件可能会被偷窥或者担心泄露,那么你可以考虑像我一样,加密你在Dropbox上的文件以及目录。这样你既可以享受Dropbox带来的自动同步的好处,又减小对Dropbox安全性的依赖.
使用encfs加密目录

Step0: 安装encfs:
在Ubuntu上
$ sudo apt-get install encfs
在Mac上如果你使用home brew(推荐!)
$ brew install encfs
或者还在使用古老的mac port
$ sudo port install encfs

Step1: 使用encfs:
首先建立一个叫~/Dropbox/Encrypted的目录。这个目录暂时还没有任何数据,但是以后你的加密过的数据和文件就会存放在这里。由于这个目录在Dropbox下,所以它会被自动同步到你的各个机器上。
然后再建立一个叫~/ToBeEncrypted的目录。这个目录将会作为一个mount point。
将Encrypted通过encfs而mount到ToBeEncrypted:
$ encfs ~/Dropbox/Encrypted ~/ToBeEncrypted
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
这里选择p 然后输入密码。这样你就创建了一个用此密码加密的volume,并且mount在了~/ToBeEncrypted这里
Step2: 把你需要加密的数据(文件或者目录都可以)copy或者move到~/ToBeEncrypted目录下:
比如我们要把一个叫MyTopSecret.txt的文件放入加密后的目录
$ mv MyTopSecret.txt ~/ToBeEncrypted
你会看见在~/Dropbox/Encrypted这个目录下,也会出现一个文件,但是是被加密过后的。
Step3: 拷贝完毕后,unmount含有未加密数据的目录
$ fusermount -u ~/ToBeEncrypted

Step4: 再次mount加密过的目录
$ encfs ~/Dropbox/Encrypted ~/ToBeEncrypted
输入密码后,那些加密过的文件就会再次以加密前的模样出现再~/ToBeEncrypted这里
使用vi加密单个文件

在encfs的基础上,你还可以再用vim给文件设置一层密码
加密码
$ vim -x filename
更换密码:
$ vim +X filename

Ref

File Encryption in Linux

Sunday, September 28, 2008

[VI]vim笔记

常用键
. 重复上一个命令
ctrl G 显示当前文件名等信息
去除^M %s/^M//g
^M = ctrl v+ ctrl M

移动
w,b 向右/左移动一个单词
ctrl f,ctrl b 向下/向上翻页
% 移动至匹配的括号
fc,Fc 向右/左移动至下一个字符c
tc,Tc 向右/左移动至一下个字符c

删除
dm 删除至移动指令m所到达的地方
di{, di} 删除当前配对的{}间所有内容
di(, di) 删除当前配对的()间所有内容


缩进
>> Indent line by shiftwidth spaces
<< De-indent line by shiftwidth spaces
5>> Indent 5 lines
5== Re-indent 5 lines
>% Increase indent of a braced or bracketed block (place cursor on brace first)
=% Reindent a braced or bracketed block (cursor on brace)
<% Decrease indent of a braced or bracketed block (cursor on brace)
]p Paste text, aligning indentation with surroundings
=i{ Re-indent the 'inner block', i.e. the contents of the block
=a{ Re-indent 'a block', i.e. block and containing braces
=2a{ Re-indent '2 blocks', i.e. this block and containing block
>i{ Increase inner block indent
<i{ Decrease inner block indent
Block Visual
ctrl+v 进入 Block Visual 模式;
用方向键控制在几行作业;
I 进入插入模式, 键入插入内容;
esc返回,这样插入的内容被应用于选中的每一行
d 删除选中的区域

如果发现无法实现上述功能,很可能是没有装完全的vim
在ubuntu或者debian下,可以

$ sudo apt-get install vim-full

编辑模式下使用上下左右键
:set nocp
或者在${HOME}/.vimrc中加入
set nocp

加密码
vim -x filename
更换密码:
vim +X filename

常用${HOME}/.vimrc的设置
  • set expandtab: 把tab置换为space
  • set ts=4: 设置tabstop为4
  • set tw=0: 设置textwidth。 一行长度超过textwidth的时候会添加line break。为0的话disable这个功能
  • set showmode: 显示当前vi工作在什么模式下
  • set nocompatible: 抛弃和vi兼容性.通常如果在插入等模式下用方向键出来ABCD之类的字母,就这样设置
  • .vimrc中, 如果要注释一行,使用双引号"


打开多个文件和在其中移动
使用tab (http://vim.wikia.com/wiki/Using_tab_pages)
  • :tabe filename 在新tab中打开另一个文件
  • :tabs 查看所有tabs
  • :tabc 关闭当前tab
  • :tabc {i} 关闭第i个tab
  • gt 上一个tab
  • gT 下一个tab

切割屏幕
:split
:split filename
:vsplit
:vsplit filename
在窗格间切换
ctrl-W 上/下


VIM Quick Reference
VIM tips and tricks