ReadLine 键绑定

bash、lftp、gdb 等都用 readline 的。
约定:

\C-a 表示 Ctrl+a
\M-a 表示 Meta+a Meta键在PC中通常为ALT键
A    表示 Shift+a
(下面括号中的\A代表Alt,\S代表Shift)

移动命令:

\C-a    移动到行首        Aheah
\C-e    移动到行末        End
\C-f    向前移动一个字符   Forward
\C-b    向后移动一个字符   Backward
\M-f    向前移动一个单词
\M-b    向后移动一个单词
\C-l    清空屏幕           cLear

\C-p    上翻,前一条命令    Previous
\C-n    下翻,后一条命令    Next

编辑命令:

\C-d       删除光标后的一个字符    \M-d         删除光标后的一个单词    Delete
\BackSpace 删除光标前的一个字符    \M-BackSpace 删除光标前的一个单词
\C-k       删除光标至行末的部分                                 Kill
\C-u       删除光标至行首的部分                                 Unix-line-discard
\C-w       删除光标前的一个单词                                 Word
\C-y       粘贴(最后删除的对象)                                 Yank
\C–       撤消

搜索历史纪录:

\C-r    连续使用 ‘C-r’ 可以查找下一个
\M-p
\M-n

补全:

\Tab    使用频率最高的功能!
\C-o    遍历补全 (未定义)
\M-?    M-=     列出所有可能选项,相当于按两次Tab键(M-? 实际按键为\A+\S+/)
\M-#    注释掉当前命令,用于将当前命令暂存于历史纪录列表(\A+\S+3)
\M-!    补全命令,通常用来补全子命令,例如 ’‘sudo’‘ 的子命令(\A+\S+1)
\M-~    补全用户名(\A+\S+’)
\M-@    补全主机名(\A+\S+2)
\M-$    补全变量(\A+\S+4)
\M-_    补全历史纪录中的纪录(\A+\S+-)
\M-*    将所有可能选项放到命令行中(\A+\S+8)

Posted in GNU/Linux | Tagged | Leave a comment

构建 Debian 软件包

看了看,终于对deb包有所悟了
http://debian.linuxsir.org/doc/inthedebianway/debian_build_package.html

1. 声明

2. Debian软件包介绍

在Debian中存在两种类型的软件包:

  • 源代码包

    源代码包, 包括一个描述源代码包的 .dsc 文件, 一个包含 gzip-tar 归档压缩格式的未经修改源码的 .orig.tar.gz 文件, 一个包含对源代码作 Debian 特有修改的 .diff.gz 文件. 可以使用 dpkg-source 打包和解压 debian 源码文档. 详见联机手册.

  • 二进制包

    二进制包以 .deb 扩展名来表示,这些文件通常称为DEB文件,其中包含可执行文件,文档,配置文件和版权信息及其它一些东西.可以使用 Debian 的 dpkg 工具解包(安装).但除去版权信息(和 changelog.Debian 文件)不讲,二进制包也可以是空的,这种软件包作为过渡包或关联包(也称虚拟包),它们的唯一的作用是用于满足依赖性.

在本文中我们将主要讲述 .deb 包的构建,源代码包的只会有少量舍己

软件包命名约定

Debian软件包命名遵循下列约定: <软件包名称>_<版本>-<Debian修订号>_<平台>.deb

例如


nano_1.3.10-2_i386.deb

软件包名称: nano
版本: 1.3.10
修订号: 2
平台: i386

3. .deb 文件的结构

参阅 Debian 的软件包管理系统介绍

4. 修改现有 .deb 文件

比如 nano(1.3.10) 需要满足以下依赖关系:


$ dpkg-deb -f nano_1.3.10-2_i386.deb depends //depends 为对应查询段

libc6 (>= 2.3.5-1), libncursesw5 (>= 5.4-5)

当系统不能满足依赖关系, 比如不能满足里来版本, 可以通过下边的方法处理, 当然这种情况下安装的nano并不一定运行正常, 这种方法可以应用于某些软件的变通安装.


$ mkdir nano //创建nano目录

$ dpkg-deb -e ./nano_1.3.10-2_i386.deb ./nano/DEBIAN //解压控制文件

$ dpkg-deb -x ./nano_1.3.10-2_i386.deb ./nano //解压程序文件

$ vi ./nano/DEBIAN/control //修改控制信息

$ dpkg-deb -b nano nano_1.3.10-2_ill.deb //重新打包

注:

下载 .deb 包的方法

  • 方法一

    运行命令


    $apt-get install -d packagename


    $aptitude install -d packagename

    将下载 .deb 文件到 //var/cache/apt/archives/ 目录

    如果管理系统数据库中的对应版本不低于源上的版本将不会下载

  • 方法二

    运行命令:


    $aptitude download packagename

    将直接执行下载操作, 将 .deb 文件下载到当前目录.

5. 从当前系统构建 .deb 包

Debian软件包: dpkg-repack 可以用来重新构建已经安装到系统中的软件包为 .deb 文件. 并包含已经修改了的配置文件. 详细新息参阅:

dpkg-repack manpages

Debian GNU/Linux Anwenderhandbuch

对于某些需要修改配置后进行大面积安装的软件包, 可以是用 dpkg-repack 重新打包, 然后分发.

运行 dpkg-repack 需要 root 权限,也可以是用 fakeroot 取代 root 权限。例如:


# aptitude install dpkg-repack

$ fakeroot -u dpkg-repack nano
dpkg-deb: building package `nano’ in `./nano_1.3.11-2_i386.deb’.

user@debian:~$ fakeroot -u dpkg-repack apt
dpkg-deb: building package `apt’ in `./apt_0.5.22_i386.deb’.

可以使用 dpkg-deb 进行验证


$ dpkg-deb -I ./nano_1.3.11-2_i386.deb
new debian package, version 2.0.
size 256488 bytes: control archive= 2749 bytes.
12 bytes, 1 lines conffiles
857 bytes, 22 lines control
3529 bytes, 51 lines md5sums
613 bytes, 21 lines * postinst #!/bin/sh
160 bytes, 5 lines * postrm #!/bin/sh
379 bytes, 20 lines * preinst #!/bin/sh
288 bytes, 14 lines * prerm #!/bin/sh
Package: nano
Priority: important
Section: editors
Installed-Size: 1452
Maintainer: Jordi Mallach <jordi@debian.org>
Architecture: i386
Version: 1.3.11-2
Replaces: pico
Provides: editor
Depends: libc6 (>= 2.3.5-1), libncursesw5 (>= 5.4-5)
Suggests: spell
Conflicts: nano-tiny (<= 1.0.0-1), pico
Conffiles:
/etc/nanorc 0f0e96f9c7e5ffe2338e79c9aacb9b9f
Description: free Pico clone with some new features
GNU nano is a free replacement for Pico, the default Pine editor. Pine is
copyrighted under a restrictive licence, that makes it unsuitable for
Debian’s main section. GNU nano is an effort to provide a Pico-like
editor, but also includes some features that were missing in the original,
such as ‘search and replace’, ‘goto line’ or internationalization support. .
(Repackaged on Fri, 26 May 2006 22:17:52 +0800 by dpkg-repack.)
Architecture: i386

tony@tony:~/doc/build_package$

$dpkg-deb -c ./nano_1.3.11-2_i386.deb
drwxr-xr-x root/root 0 2006-05-26 22:17:52 ./
drwxr-xr-x root/root 0 2006-05-26 22:17:52 ./etc/
-rw-r–r– root/root 13611 2006-04-06 06:22:03 ./etc/nanorc
drwxr-xr-x root/root 0 2006-05-26 22:17:52 ./usr/
drwxr-xr-x root/root 0 2006-05-26 22:17:52 ./usr/share/
drwxr-xr-x root/root 0 2006-05-26 22:17:52 ./usr/share/doc/
drwxr-xr-x root/root 0 2006-05-26 22:17:52 ./usr/share/doc/nano/
-rw-r–r– root/root 3419 2002-07-19 09:08:58 ./usr/share/doc/nano/BUGS.gz
-rw-r–r– root/root 1847 2005-08-30 02:29:02 ./usr/share/doc/nano/AUTHORS
-rw-r–r– root/root 102030 2006-03-30 14:34:43 ./usr/share/doc/nano/changelog.gz
-rw-r–r– root/root 2338 2005-03-20 05:33:13 ./usr/share/doc/nano/README
-rw-r–r– root/root 3234 2006-03-17 01:57:28 ./usr/share/doc/nano/THANKS
-rw-r–r– root/root 2206 2005-06-08 10:28:06 ./usr/share/doc/nano/TODO
-rw-r–r– root/root 1066 2003-03-24 21:09:26 ./usr/share/doc/nano/UPGRADE

…..

6. 使用源提供的源代码构建 .deb 包

  • 下载源码包

    APT提供了一套简便的方法帮你获得发布版中众多程序的源代码以及创建一个.deb所需的所有文件。

    首先, 在 /etc/apt/sources.list 文件中加入 deb-src 条目. 详细参阅 APT HOWTO

    然后, 运行命令


    # apt-get update


    # aptitude update

    就可以用下面的命令下载源码包:


    # apt-get source packagename


    # aptitude source packagename

    通常会下载三个文件:.orig.tar.gz,.dsc 和 .diff.gz。对于 Debian 专用的软件包,最后一个文件不会下载,第一个文件的文件名中没有“orig”项。

    dpkg-source 读取 .dsc 文件信息,将源码包解包到 packagename-version 目录,下载下来的源码包中有一个 debian/ 目录,里面是创建 .deb 包所需的文件。

    例如:


    $ apt-get source nano
    Reading package lists… Done
    Building dependency tree… Done
    Need to get 1199kB of source archives.
    Get:1 http://ftp.us.debian.org testing/main nano 1.3.11-2 (dsc) [706B]
    Get:2 http://ftp.us.debian.org testing/main nano 1.3.11-2 (tar) [1173kB]
    Get:3 http://ftp.us.debian.org testing/main nano 1.3.11-2 (diff) [25.4kB]
    Fetched 1199kB in 3m46s (5287B/s)
    … …
    dpkg-source: extracting nano in nano-1.3.11
    dpkg-source: unpacking nano_1.3.11.orig.tar.gz
    dpkg-source: applying ./nano_1.3.11-2.diff.gz

    做相应调整后, 在源代码的根目录 nano-1.3.11 下运行:


    # dpkg-buildpackage -rfakeroot -uc -b

    将代码编译成为软件包.

    想要下载的源码包自动编译成软件包,只需在命令行中加上 -b,例如:


    # apt-get -b source packagename

    请在下载包所在的目录中运行上面的命令。


    # dpkg -i file.deb

    apt-get的source命令与它的其它命令有所不同,普通用户权限就可以运行source命令,指定文件被下载到用户调用 apt-source package 命令时所处的目录中。

  • 编译源码包所需的软件包

    通常,编译源码包时要用到某些头文件和共享库,所有的源码包的管理文件 (control file) 中都有一个域 "Build-Depends:", 域中指出了编译该源码包需要哪些附加包。

    如果你仅仅想检查一下编译当前包需要哪些相关软件包,可以使用 apt-cache show 命令的一个变种,它将显示软件包信息中有关 Build-Depends 的行。


    $ apt-cache showsrc nano|grep Build-Depends
    Build-Depends: dpkg-dev (>= 1.13.9), libncurses5-dev, libncursesw5-dev, libslang2-dev, debhelper (>= 5.0.22), dpatch

    APT 提供了一个简单的方法下载这些附加包,你只需运行 apt-get build-dep package, 其中 package 就是你打算编译的源码包名称。例如:


    # apt-get build-dep nano
    Reading package lists… Done
    Building dependency tree… Done
    The following NEW packages will be installed:
    build-essential dpatch g++ libncursesw5-dev libslang2-dev
    0 upgraded, 5 newly installed, 0 to remove and 0 not upgraded.
    Need to get 986kB of archives.
    After unpacking 2806kB of additional disk space will be used.
    Do you want to continue [Y/n]?

    这些用于 nano 正确编译指定源码包的附加包将会被安装。注意这个命令不能用来搜索软件的源码包,你得另外运行 apt-get source 下载源码包。

7. 对现有文件打包:

  • 创建工作目录

    构建模拟根目录, 比如 fakeroot :


    $ mkdir fakeroot

  • 部署文件

    在 fakeroot 下构建模拟文件系统, 将欲打包文件放置到对应目录

    形如:


    tony@tony:~$ tree fakeroot/
    fakeroot/
    |– DEBIAN
    | |– control
    | `– preinst
    `– usr
    `– share
    `– doc
    `– securing-debian-howto.zh-cn
    |– ap-bind-chuser.zh-cn.html
    |– ap-bridge-fw.zh-cn.html
    |– ap-checklist.zh-cn.html
    … …

  • 创建配置文件

    在 fakeroot 下创建DEBIAN目录用于放置控制文件 比如:

    control preinst postinst prerm postrm 等, 只有 control 是必须的, 其他为可选.

    可以在 /var/lib/dpkg/info 目录下找到这些脚本的范例

    比如


    tony@tony:~/fakeroot/DEBIAN$ cat control

    Package: securing-debian-howto.zh-cn
    Priority: extra
    Section: doc
    Maintainer: tony <etony@tom.com>
    Architecture: all
    Version: 3.0
    Description: Securing Debian Manual
    This manual describes the security of the Debian GNU/Linux operating system and within the Debian project. It covers some of the common tasks involved in setting up a secure user and network environment, gives information on the security tools available, steps to take before and after a compromise and also describes how security is enforced in Debian by the security team. The document includes a step by step hardening guide and within the appendix there is detailed information on how to setup an intrusion detection system and a bridge firewall with Debian GNU/Linux.

    tony@tony:~/fakeroot/DEBIAN$ cat preinst
    #! /bin/sh

    echo "."
    echo "."

    echo "Welcome to install Securing Debian HOWTO. "
    echo "press any key to continue… "
    read
    exit 0

  • 生成 .deb 包

    在 fakeroot 目录外执行:


    $ dpkg -b fakeroot securing-debian-howto-zh-cn.deb

    dpkg-deb: building package `securing-debian-howto.zh-cn’ in `securing-debian-howto-zh-cn.deb’.

    将会在当前目录下生成 securing-debian-howto-zh-cn.deb 包

  • 检查包内容

    可是用以下命令检查:


    $ dpkg -c securing-debian-howto-zh-cn.deb

    $ dpkg -I securing-debian-howto-zh-cn.deb

8. 源代码构建

这次以 leafpad 为例, leafpad 的当前版本为 0.8.9

  • 下载程序源代码


    #wget http://savannah.nongnu.org/download/leafpad/leafpad-0.8.9.tar.gz

  • 创建工作目录


    # mkdir leafpad

    #mv leafpad-0.8.9.tar.gz leafpad/

    #cd leafpad

    #tar zxvf leafpad-0.8.9.tar.gz

    #cd leafpad-0.8.9

  • 安装打包环境

    运行一下命令,安装编译 leafpad 所需的环境


    # apt-get install dh-make dpkg-dev g++ patch make libc6-dev fakeroot libgtk2.0-dev cdbs debhelper pkg-config gnome-pkg-tools

  • Debian 初始化


    # dh_make -e etony@tom.com -f ../leafpad-0.8.9.tar.gz

    Type of package: single binary, multiple binary, library, kernel module or cdbs?
    [s/m/l/k/b] s

    Maintainer name : tony
    Email-Address : etony@tom.com
    Date : Sun, 28 May 2006 22:38:08 +0800
    Package Name : leafpad
    Version : 0.8.9
    License : blank
    Type of Package : Single
    Hit <enter> to confirm:
    Done. Please edit the files in the debian/ subdirectory now. leafpad
    uses a configure script, so you probably don’t have to edit the Makefiles.

  • 构建配置文件

    根据需求修改 debian/ 目录下的内容

    修改 changelog, control,

    以下为自动生成的 changelog, control 配置文件框架


    /leafpad/leafpad-0.8.9/debian$ cat control
    Source: leafpad
    Section: unknown
    Priority: optional
    Maintainer: tony <etony@tom.com>
    Build-Depends: debhelper (>= 4.0.0), autotools-dev
    Standards-Version: 3.6.2

    Package: leafpad
    Architecture: any
    Depends: ${shlibs:Depends}, ${misc:Depends}
    Description: <insert up to 60 chars description>
    <insert long description, indented with spaces>

    /leafpad/leafpad-0.8.9/debian$ cat changelog
    leafpad (0.8.9-1) unstable; urgency=low

    * Initial release Closes: #nnnn (nnnn is the bug number of your ITP)

    — tony <etony@tom.com> Sun, 28 May 2006 22:38:08 +0800

    如有需要自己,根据示例文件 *.ex 生成 postinst, postrm, prerm 等脚本文件

  • 构建 .deb 包


    # dpkg-buildpackage -rfakeroot -uc -b

    如果您已经多次运行了上边的命令, 也可以使用下边的命令快速构建临时 .deb 包:


    #fakeroot debian/rules binary

    将会在其上一级目录生成 leafpad_0.8.9-1_i386.deb

9. 参考文档

Posted in GNU/Linux | Tagged | Leave a comment

PGP (Pretty Good Privacy) and GnuPG (GNU Privacy Guard) notes

转自:http://www.math.utah.edu/~beebe/PGP-notes.html

还有几篇文章也很有用:
The GNU Privacy Handbook http://www.gnupg.org/gph/en/manual.html
GnuPG Gentoo User Guide   http://www.gentoo.org/doc/en/gnupg-user.xml
Gnu Privacy Guard Mini Howto http://dewinter.com/gnupg_howto/english/GPGMiniHowto.html

About PGP and GnuPG

PGP software provides for highly-secure encryption and decryption of data, and for creating and verifying digital signatures.

A secure encrypted channel permits people to communicate with considerable confidence that others (including big unnamed government agencies) cannot eavesdrop, even if the encrypted traffic is intercepted (as anything that traverses the Internet can be, with the right tools, and either clandestine access or suitable privileges).

Digital signatures are useful for verifying that all parties see the same file contents, and that any tampering with those contents can be detected.

The GNU Privacy Guard (GnuPG) package is a “complete and free replacement for PGP. Because it does not use the patented IDEA algorithm, it can be used without any restrictions. GnuPG is a RFC2440 (OpenPGP) compliant application.”

The short reading list at the end of this document leads to important comprehensive books on this subject.


E-mail encryption

Some e-mail clients implement support for sending and receiving encrypted messages. While that is certainly convenient, it leaves users in a (usually) undesirable state of ignorance about what is going on. This section tells how you can do each step yourself.

To exchange secret messages with me, proceed as follows:

  1. Fetch my public key from my Web site. The key file looks exactly like this (all lines should be flush left):

    —–BEGIN PGP PUBLIC KEY BLOCK—–
    Version: 2.6.2

    mQCNAzWBPeIAAAEEANI3Ptvt8e0ur8iiN9u2sYTJwaLeeDU/+W2umnsWskR9COQm
    UklyxPVZF6M+EebaalqhL6VqqvWh7n0CxMD5puxxoBAPPKUM8bAks7j42QZMx8Oz
    xvzDSk4bqTasmGOBg667P9jH6AcOjKP08zfwQb5Qm3TCFdsruWfhK324XxlBAAUR
    tChOZWxzb24gSC4gRi4gQmVlYmUgPGJlZWJlQG1hdGgudXRhaC5lZHU+
    =ISkv
    —–END PGP PUBLIC KEY BLOCK—–

    Save it in a temporary file, say foo.pubkey.

  2. Add it to your pgp public key ring:

    % pgp -ka foo.pubkey

    You only need to do this, and the preceding, step once.

  3. Create a file, say foo.msg, with your secret message, and encrypt it with my public key:

    % pgp -eats foo.msg

    PGP will ask for your secret key in order to be able to unlock your key ring. Then it will ask for my public key’s user ID to encrypt your message. It will end with:

    Transport armor file: foo.msg.asc

  4. Mail that `transport armor’ file to me:

    Mail -s "Secret message" < foo.msg.asc beebe@math.utah.edu

    That is the simplest way in Unix to mail a text file to someone. However, any decent mail client supports insertion of files into outgoing messages, so you could just insert foo.msg.asc into a message that way using your favorite mail program, possibly prefixing the insertion with some explanatory comments.

    If you give me a copy of your public key, which you can extract into a file that PGP will prompt you for, like this:

    % pgp -kxa

    or

    % pgp -kxa your-username@your-host

    then I can add it to my public key ring, and use it to encrypt messages to send back to you that only you can read.

    Your ability to read such a message from me to you that was encrypted with your public key is proof that your public key was not compromised during transmission to me, such as via e-mail, or a Web connection. On the other hand, if you cannot read my message, then we’d both better duck, because someone nasty is attacking us.


E-mail decryption

When you receive a message that has been encrypted with your public key, save it in a file, say secret.asc, and then decrypt it like this:

% pgp secret.asc
Pretty Good Privacy(tm) Version 6.5.8
(c) 1999 Network Associates Inc.

Export of this software may be restricted by the U.S. government.

File is encrypted. Secret key is required to read it.

Key for user ID:
1024-bit DSS key, Key ID 0x…….., created …./../..
Key can sign.

You need a pass phrase to unlock your secret key.

Enter pass phrase:
Good signature from user "…".
Signature made 2005/04/07 14:25 GMT

Plaintext filename: secret

The resulting output file secret contains the plaintext of the encrypted message.

If the plaintext is really secret, then it is a bad idea to save it in a disk file, where it could possibly be read by others, and be recorded in long-term filesystem backups. The solution is to display it on the screen with the more pager:

% pgp -m secret.asc
…as before…
Enter pass phrase:
Good signature from user "…".
Signature made 2005/04/07 14:25 GMT
…plaintext appears on the screen here…

Here is the decryption procedure using GnuPG:

% gpg secret.asc
You need a passphrase to unlock the secret key for
user: "…."
2048-bit ELG-E key, ID …….., created 2003-01-30 (main key ID ……..)

gpg: encrypted with 2048-bit ELG-E key, ID …., created ….-..-..
"…."
gpg: Signature made Thu Apr 07 08:38:51 2005 MDT using DSA key ID ……..
gpg: Good signature from "…."

There does not appear to be a way with GnuPG to send the plaintext directly to a screen pager utility.


Digital signature creation and verification

Digital signatures can be created as part of a document, in the form of a short wrapper, or in separate files. Both forms are useful: e-mail messages would normally use the first way, while software distributions would use the second approach.

To create an integrated digital signature for a file, say, foo.msg:

% echo "This is a message." > foo.msg

% cat foo.msg
This is a message.

% pgp -sta foo.msg

Enter pass phrase: XXXX
Pass phrase is good.
Key for user ID: Nelson H. F. Beebe <beebe@math.utah.edu>
1024-bit key, Key ID B85F1941, created 1998/06/12
Just a moment….
Clear signature file: foo.msg.asc

This produced a signed wrapper that I can give to someone.

% cat foo.msg.asc
—–BEGIN PGP SIGNED MESSAGE—–

This is a message.

—–BEGIN PGP SIGNATURE—–
Version: 2.6.2

iQCVAwUBPjlRxWfhK324XxlBAQFdhgP/bdHMqstLCvXG8pGIfc7OzgUySzjewx1T
GU+zi7aJzcj4WWrOxsSqceNyroIMTXpwBOwb1OP8kbBzGr+TW9Kzb+1P/UdMmnHH
qgsZbXAcf3dVUwEPhrgn5XhxXk6mPocAvL0/7VhwHClbGPAefvrcKhkAyrSfxIP2
i697b7szCeU=
=5oN9
—–END PGP SIGNATURE—–

PGP makes this file readable only by its creator, but in this case, we want it to be readable by anyone:

% chmod a+r foo.msg.asc

At a remote site, the validity of the digital signature can be checked, and the wrapper removed, by someone else like this:

% pgp foo.msg.asc

File has signature. Public key is required to check signature. .
Good signature from user "Nelson H. F. Beebe <beebe@math.utah.edu>".
Signature made 2003/01/30 16:25 GMT

Plaintext filename: foo.msg

You can also use GnuPG for signature verification:

% gpg foo.msg.asc
gpg: WARNING: using insecure memory!
gpg: please see http://www.gnupg.org/faq.html for more information
gpg: Signature made Thu Jan 30 09:24:37 2003 MST using RSA key ID B85F1941
gpg: Good signature from "Nelson H. F. Beebe <beebe@math.utah.edu>"
gpg: checking the trustdb
gpg: no ultimately trusted keys found
gpg: WARNING: This key is not certified with a trusted signature!
gpg: There is no indication that the signature belongs to the owner.
Primary key fingerprint: 7C18 7199 BC82 5EAB 06EB 9B96 FD9E 0E97 A93C 57C2

Suppose someone had tampered with the message, changing, say, a message, to an altered message. We can duplicate that tampering like this:

% sed -e "s/a message/an altered message/" foo.msg.asc > foo2.msg.asc

Signature verification now fails:

% pgp foo2.msg.asc

File has signature. Public key is required to check signature. .
WARNING: Bad signature, doesn’t match file contents!

Bad signature from user "Nelson H. F. Beebe <beebe@math.utah.edu>".
Signature made 2003/01/30 16:25 GMT

Plaintext filename: foo2.msg

To create an ASCII signature in a separate .asc file:

% pgp -stab foo.msg

Enter pass phrase: XXXX
Pass phrase is good.
Key for user ID: Nelson H. F. Beebe <beebe@math.utah.edu>
1024-bit key, Key ID B85F1941, created 1998/06/12
Just a moment….
Transport armor file: foo.msg.asc

Here is what the signature file looks like:

% cat foo.msg.asc
—–BEGIN PGP MESSAGE—–
Version: 2.6.2

iQCVAwUBPjlTkWfhK324XxlBAQEhyAQAo5XdKEeOpClpCmiSRfc+D/SL5xg21QRy
wNOXEEZKEMhDeE7CWTWJIWyh9nbI6MUF93aLcEwdAHgv0+B2fdm7Fefe1+p+P6HU
Ts54zBEoMdj10NiLTRdtES37V/0wj/HXkJW3T6WU9EeULv3Mk0133Q16OsIi1xsv
Cy2Ky9VtCiA=
=bnlu
—–END PGP MESSAGE—–

To create a binary signature in a separate .sig file:

% pgp -sb foo.msg

Signature file: foo.xxx.sig

To verify the signature at some other site, you can specify either the base filename, or the signature filename.

% pgp foo.msg

File ‘foo.msg.asc’ has signature, but with no text.
Text is assumed to be in file ‘foo.msg’.
Good signature from user "Nelson H. F. Beebe <beebe@math.utah.edu>".
Signature made 2003/01/30 16:32 GMT

Signature and text are separate. No output file produced.

If the basename is used, and both .asc and .sig files exist, the .asc file is used for the signature.

The GNU Project archives and the ftp://ftp.math.utah.edu/pub/ archives use binary .sig signature files.

At various places in our local FTP and Web filesystems, you can find files named MD5SUM.asc. They contain MD5 checksums of files in the directory, plus an embedded signature. These were made like this:

% md5sum * > MD5SUM
% pgp -sta MD5SUM

A line in one such file looks something like this:

f6a8f9fa5d8d9872824d929db192405e hoc-7.0.6.beta.tar.gz

By verifying the digital signature on MD5SUM.asc with pgp MD5SUM.asc, you can be sure that the MD5SUM file matches what I created here. If you now fetch the indicated .tar.gz file, you can reproduce the checksum line at your site like this:

% md5sum hoc-7.0.6.beta.tar.gz
f6a8f9fa5d8d9872824d929db192405e hoc-7.0.6.beta.tar.gz

The checksum match verifies that the .tar.gz file was not corrupted during transmission, and your copy matches mine exactly.

Many of the archives also contain separate .sig detached signature files, such as the hoc-7.0.6.beta.tar.gz.sig file for the above example.


Key servers for public keys

How do you know that someone’s public key hasn’t been tampered with? An attacker who managed to do this would been able to decrypt messages sent to your intended recipient, but that person would be unable to do so.

The solution to this problem is for users who create a new public key to immediately register it with one or more neutral third parties, called public key servers, who act as (presumably incorruptible) escrow agents.

There is a small network of such servers for PGP keys distributed across several countries. Registration with just one is sufficient, since they exchange their public key archives, although it may take several days for a newly-registered key to propagate widely. Here is a short list of some public key servers:

Key servers allow you to lookup keys by email addresses and by personal name. For example, at one of them, a search for beebe@math.utah.edu produces:

Public Key Server -- Index ``beebe@math.utah.edu ''

Type bits /keyID Date User ID
pub 1024D/A93C57C2 2003/01/30 Nelson H. F. Beebe <beebe@math.utah.edu>
pub 1024R/B85F1941 1998/06/12 Nelson H. F. Beebe <beebe@math.utah.edu>

As shown in this example, the keyID values are hyperlinked: selecting one of them leads to a page with the public key block for that person. The email addresses are also hyperlinked: they lead to a list of keys registered by the person with that address.

A search for just Beebe turns up dozens of keys registered by people with that name, along with their email addresses. A search for the more common name Nelson turns up hundreds of keys. A search for Nelson Utah turned up only three keys when this experiment was made: the above two, plus a third one. Thus, you can usually find a key, even when you don’t know the person’s exact name or email address, but you do know part of their name or location.

You can also search for keyIDs at some key servers, but you need to make sure that the keyID is prefixed with 0x (for hexadecimal). For example, in my case, search for 0xA93C57C2 instead of A93C57C2. Search by keyID is useful because signature verification may report just the keyID, without an associated human name or email address.

gpg can search for keys at keyservers specified in your $HOME/.gnupg/gpg.conf file:

% gpg –search 0xA93C57C2

gpg: searching for "0xA93C57C2" from HKP server wwwkeys.pgp.net
Keys 1-1 of 1 for "0xA93C57C2"
(1) Nelson H. F. Beebe <beebe@math.utah.edu>
1024 bit DSA key A93C57C2, created 2003-01-30
Enter number(s), N)ext, or Q)uit > q

You can also specify a keyserver on the command line:

% gpg –keyserver http://pgp.mit.edu/ –search 0xA93C57C2

gpg: searching for "0xA93C57C2" from HKP server pgp.mit.edu
Keys 1-1 of 1 for "0xA93C57C2"
(1) Nelson H. F. Beebe <beebe@math.utah.edu>
1024 bit DSA key A93C57C2, created 2003-01-30
Enter number(s), N)ext, or Q)uit > q

If you select a key by number from the displayed list, gpg automatically adds it to your GnuPG keyring (but not to yo …

Posted in GNU/Linux | Tagged | Leave a comment

如何使用dm-crypt和LUKS加密硬盘 (转)

加密硬盘技术很有用,转载一下,将来一定用的着:
http://www.rainking.cn/blog/?p=17#comment-641

申明:

本文已发布于《Linuxer》电子杂志第十期。转载和使用请与Rainking联系,联系方式:http://www.rainking.cn/blog/?page_id=4。Linuxer主页:www.linuxer.cn

介绍
动机
如今,安全保密工作已经成为我们日常生活中的关键要素,无论有意还是无意。安全保密工作的范围非常宽广,其中有一项就是计算机安全保密。

在这个教程中,我将介绍如何在(X)Ubuntu Feisty下使用dm-crypt和LUKS加密整个硬盘。在此文的撰写过程中,我搜集了网上很多信息和教程,然后将它们整理到一起,这些信息和教程可以通过以下的方式访问到:
http://www.hermann-uwe.de/blog/howto-disk-encryption-with-dm-crypt-luks-and-debian
https://systemausfall.org/wikis/howto/CryptoPartitionHowTo
– irc.freenode.org的ubuntu频道

警告
这个教程会摧毁硬盘上的所有数据,所以建议你在操作中选择硬盘的时候非常的仔细和小心。不要用它来加密你安装Linux的硬盘。其实,加密一个硬盘的初衷本来就是为了数据存储。

一些法律相关事项
有很多加密方法,其中最常提到的是提供了极大plausible deniability的true-cypt双层加密方法。(Rainking注:这里plausible deniability非常不好翻译,故保留英文原文,方便大家理解。据我的研究,plausible deniability是指做了坏事而能不留证据的行为,比如用电击对人进行体罚而不留下伤口)这意味着如果某人看见你有一块很大的硬盘但是只有一点点资 料在上面并且这些资料有点像被删除的数据,那么这个人完全有理由推断出这是一个加密的硬盘。这时候你可能就要被逼迫(被法官逼迫或者被坏人逼迫)交出解密 的方法。所以你可以交出加密低机密数据的解密方法而不交出加密高机密数据的加密方法。而逼迫你的人并不能确认你所解密的数据是不是整个硬盘的全部数据。 (Rainking注:关于true-cypt双层加密方法这里并没有篇幅详细说明,请读者自己研究^_^,不仔细研究了解一下,上述这段话可不好理解 噢)

但是,这并不一定是好事,因为一旦你使用了双层加密方式,那么别人将永远不会相信你给出了解密的所有关键字以解开第二层加密文件。这就使得使用双层加密的用户在某些时刻会陷入无法证明自己清白的境地。

不过plausible deniability对我来说并不重要。因为我生活在欧洲的一个认可欧洲人权宪章的国家。我拥有在面对任何法律情况都保持沉默的权利。

这意味着如果法庭传唤我让我给出解密加密数据的密钥的话,对我来说并没有什么法律意义。如果法庭硬是这么做了,我可以去斯特拉斯堡的欧洲人权法庭告它,并且有很大概率胜诉。

在某些国家,你需要对所有的通过你的互联网帐户传播的信息负责,哪怕你不知道这些信息被传播了或者你没有做任何事情去促使这些信息传播。这种情况下,你硬盘上的信息就不必要被作为证据了(当然了,要是能作为证据更好),这时候,加密的磁盘就不能保护你啦。

因此,我只把这篇文章的重点关注在并不提供高级plausible deniability 多层次加密的dm-crypt和LUKS上。

注:作为一个瑞士的法律研究生(Rainking注:!•#¥%……—*怪不得这家伙写得英文我看不懂呢!大家同情我吧!这篇文章实在太难翻 了!),我只是站在瑞士法律的角度看以上问题。在欧洲的其它国家,可能会有不同之处,但是保障人权自由的基本原则应该是相同的。而且我使用的语法和词汇可 能并不是完全符合英语标准的法律术语,但是基本意思应该是差不多的。总之就是不要把之上的所有陈述当作一个严格的司法解释就对了。

安装必要软件
我使用的Linux发行版本是Xubuntu Feisty。所以所述方法应该可以同样使用在所有Ubuntu版本和其它基于Debian的发行版本上。

安装软件很简单,在终端输入:
sudo aptitude install cryptsetup hashalot

准备你的硬盘
首先我们要在硬盘中加入随机的数据。这可以使得外人无法猜测到底硬盘上有多少隐藏数据。我使用的是dd命令实现添加随机数据的,这个操作需要一段时间,在终端输入:
sudo dd if=/dev/urandom of=/dev/HARDDISK
用你的实际硬盘名替换HARDDISK,比如:hda或者hdb或者sda或者sdb。
这将运行一段时间。我的运行结果如下:
hyper@xubi:/dev$ sudo dd if=/dev/urandom of=/dev/hda
dd: writing to `/dev/hda’: No space left on device
312581809+0 records in
312581808+0 records out
160041885696 bytes (160 GB) copied, 90679.8 seconds, 1.8 MB/s

安装一些内核模块
为了使用dm-crypt我们需要再安装一些内核模块,在终端输入:
sudo modprobe aes dm-crypt dm_mod

如果你希望它们在启动的时候被载入,请编辑/etc/modules,在终端输入:
sudo nano /etc/modules
然后在文件末尾加入如下内容:
# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with “#” are ignored.
fuse
lp
aes
dm-crypt
dm_mod

fuse和lp已经默认存在于我的文件中了,有可能你的文件中并没有这些行,或者有其它行,这不要紧,你只需要在末尾加上aes, dm-crypt和dm_mod就可以了。加完以后可以按下ctrl-x,然后NANO会问你是否需要保存修改的文件。按Enter键2次,一次确认保 存,一次确认文件名。(Rainking注:关于NANO的介绍和教程请参见以前的杂志)

创建加密盘
在终端输入以下命令以创建分区:
sudo cryptsetup luksFormat /dev/HARDDISK

映射加密分区
在终端输入以下命令映射加密分区:
sudo cryptsetup luksOpen /dev/HARDDISK DEVICENAME
现在加密分区已经映射到了/dev/mapper/DEVICENAME下

格式化加密分区
在终端输入以下命令格式化分区:
sudo mkfs.ext3 /dev/mapper/DEVICENAME

挂载分区
首先创建一个挂载点:
sudo mkdir /media/DEVICENAME
然后挂载分区到挂载点:
sudo mount /dev/mapper/HARDDISK /media/DEVICENAME

如果你因为某些原因卸载了分区,并希望之后再挂载它,你并不需要再次创建文件系统。你只需要在终端输入:
sudo cryptesetup luksOpen /dev/HARDDISK DEVICENAME
sudo mount /dev/mapper/HARDDISK /media/DEVICENAME

开机自动挂载
为了开机自动挂载分区,你需要编辑/etc/crypttab,在文件末段添加如下内容:
DEVICENAME /dev/HARDDISK none luks,check=ext2,retry=5
当然你需要把它添加入/etc/fstab文件,如下所示:
# CryptoDevices
/dev/mapper/DEVICENAME /media/HARDDISK auto defaults 0 0

在启动的时候,你需要输入加密设备的密码才能开机。你有最多5次机会输入密码,如果超过5次输入密码错误,系统将会不挂载加密设备启动。进入系统以后,你仍然可以手动的挂载它。

添加删除密钥
你可以为一个加密分区添加多个密钥或者删除这些密钥,添加密钥需要在终端输入:
sudo cryptsetup luksAddKey /dev/HARDDISK
删除密钥则在终端输入:
sudo cryptsetup luksDelKey /dev/HARDDISK

卸载分区
只要你有足够的权限,你就可以使用dmsetup命令,你可以显示设备映射,观看哪个设备是可用的,即便并没有被挂载。从这种意义上看,这个设备在一定程度上已经被解密了。为了防止出现以上情况,你可以运行以下命令以正确卸载设备:
sudo umount /media/DEVICENAME && sudo cryptsetup luksClose HARDDISK
我创建了以下一个小shell程序以实现我的需要,编辑~/umount.sh输入以下内容:
#!/bin/bash
sudo umount /media/DEVICENAME && sudo cryptsetup luksClose HARDDISK
然后赋予文件可执行权限:
sudo chmod a+x ~/umount.sh
最后你还可以给它创建一个图标,具体过程随桌面环境各有不同,这里就不赘述了。

尾注
现在你已经拥有了你自己的加密分区。你可以交换使用dm-crypt和lucks来看看它们到底有什么不同。我在这篇文章中使用了整个硬盘,因为我在测试 只用硬盘的某个分区作实验的时候遇到了一些问题。对于我来说这不是什么问题,因为我是希望我的整个硬盘都被加密的。但是其它读者可能就要自己研究如何只加 密一个分区了。Enjoy!

Posted in GNU/Linux | Tagged | 2 Comments

dpkg, apt 使用

#资料来源:
http://debian.linuxsir.org/doc/inthedebianway/Debian_Tools_apt.html
http://debian.linuxsir.org/doc/inthedebianway/Debian_Tools_dpkg.html

如果仅想了解某软件包的与哪些软件包关联, 可运行:
#apt-cache depends mailx

查询哪些包依赖于mysql-server
#apt-cache rdepends mysql-server

如果要将这两种查询信息合并到一起, 则可以使用:
#apt-cache showpkg mysql-server

获得某个软件包的详细信息
#apt-cache show mysql-server

检查软件包的状态
#apt-cache policy packagename

下载软件的源代码
#apt-get source packagename
注: sources.list 中应该有 deb-src 源

安装软件包源码的同时, 安装其编译环境
#apt-get build-dep packagename
注: sources.list 中应该有 deb-src 源

如果在安装过程中出现中断, 然后你发现该软件包既不能重装又不能删除, 试试下面两个命令:
# apt-get -f install
# dpkg –configure -a

重新配置一个软件
#dpkg –configure

#dpkg-reconfigure pkgname

列出软件包的内容:
#dpkg-deb -c nano_1.3.10-2_i386.deb

查看软件包的信息
#dpkg-deb -I nano_1.3.10-2_i386.deb

#dpkg -i pkgname
安装一个deb包过程可分解为:
#dpkg –unpack
#dpkg –configure

解包可能包括一下步骤:
    * 将控制文件解压到临时目录.
    * 运行 preinst(如果有的话). 通常为停止相关服务.
    * 解压配置文件到 /etc 目录, 并添加.dpkg-new 后缀, 以防止冲突.
    * 解压 data.tar.gz 到系统根目录,(–root=dir).
    * 将控制文件解压到 /var/lib/dpkg/info 目录并添加软件名前缀. 对数据库进行更新.
    * 数据库中将软件包的状态设置为"unpacked".
仅仅解包, 并不能确保软件可以正常运行

配置过程可能包括一下步骤:
    * 询问对配置文件的处理方法, 覆盖当前版本, 还是不做处理.(当软件升级时会碰到这种情况)
    * 运行 postinst 脚本
    * 将软件包标记为 "installed"
如果想再次修改配置选项, 可以运行:
#dpkg-reconfigure nano

删除
#dpkg -r nano
    * 首先运行 prerm 脚本(如果有的话).
    * 然后, 保留配置文件, 其他文件全部删除.
    * 删除 /var/lib/dpkg/info 目录下软件包的所有配置文件, 保留postrm和list文件.
    * 最后, dpkg 在数据库中将软件状态修改为删除.
   
清除
#dpkg -P nano
    * 删除所有的文件. 所有的文件都被解除了(从系统中删除了).
    * 运行postrm脚本.如果还存在,运行postrm脚本.
    * 删除 postrm 和 list 文件.保留的两个文件,从系统中解除postfix.postrm和postfix.files.
    * 在dpkg的数据库中将软件包标记为未安装

dpkg vs rpm

    * 列出系统中安装的软件包
        o rpm -qa
        o dpkg –list
    * 列出软件包信息
        o rpm -qi pkgname
        o dpkg –status pkgname
    * 列出一个包所安装的文件
        o rpm -ql pkgname
        o dpkg –listfiles pkgname
    * 列出本地包文件的信息
        o rpm -qpi file.rpm
        o dpkg –info file.deb
    * 列出本地包文件所含文件
        o rpm -qpl file.rpm
        o dpkg –contents file.deb
    * 安装本地包
        o rpm -i file.rpm
        o dpkg –install file.deb
    * 从系统中清除包
        o rpm -E pkgname
        o dpkg –purge pkgname
    * 查询文件归属
        o rpm -qf file
        o dpkg –search file

Posted in GNU/Linux | Tagged | Leave a comment