TranslateProject/published/201406/How to manage passwords from the command line on Linux.md
wxy a71aa7de9e renamed: 10 Database Tools For Linux Users To Use!.md -> 201406/10 Database Tools For Linux Users To Use!.md
renamed:    10 Linux Platforms Meant For Embedded Systems.md -> 201406/10 Linux Platforms Meant For Embedded Systems.md
	renamed:    20140527 4MLinux 9.0 Beta Is a 55 MB Operating System That Has It All.md -> 201406/20140527 4MLinux 9.0 Beta Is a 55 MB Operating System That Has It All.md
	renamed:    20140527 A Complete Historical Timeline of Linux Evolution.md -> 201406/20140527 A Complete Historical Timeline of Linux Evolution.md
	renamed:    20140528 Setup Backup Server Using Bacula And Webmin On Ubuntu 14.04.md -> 201406/20140528 Setup Backup Server Using Bacula And Webmin On Ubuntu 14.04.md
	renamed:    20140528 Why We Shouldn't Accept Bad Linux Ports.md -> 201406/20140528 Why We Shouldn't Accept Bad Linux Ports.md
	renamed:    20140529 Add Windows Like Bottom Taskbar In Ubuntu Unity 14.04.md -> 201406/20140529 Add Windows Like Bottom Taskbar In Ubuntu Unity 14.04.md
	renamed:    20140529 Command Line Tuesdays--The Introductory.md -> 201406/20140529 Command Line Tuesdays--The Introductory.md
	renamed:    20140529 How To Share Disks In VirtualBox Between Linux Guest OS.md -> 201406/20140529 How To Share Disks In VirtualBox Between Linux Guest OS.md
	renamed:    20140529 Install RainLoop Webmail (A Web Based Email Client) using 'Nginx and Apache' in Arch Linux.md -> 201406/20140529 Install RainLoop Webmail (A Web Based Email Client) using 'Nginx and Apache' in Arch Linux.md
	renamed:    20140529 What is a good terminal emulator on Linux.md -> 201406/20140529 What is a good terminal emulator on Linux.md
	renamed:    20140529 Why No Flash Support for Linux Is Good for Open Source.md -> 201406/20140529 Why No Flash Support for Linux Is Good for Open Source.md
	renamed:    20140530 Fix 'Cannot Add PPA' Error In Ubuntu 14.04 and Linux Mint.md -> 201406/20140530 Fix 'Cannot Add PPA' Error In Ubuntu 14.04 and Linux Mint.md
	renamed:    20140530 How To Install Linux On A MacBook Pro Retina.md -> 201406/20140530 How To Install Linux On A MacBook Pro Retina.md
	renamed:    20140530 Linux script command--A recorder inside your Terminal.md -> 201406/20140530 Linux script command--A recorder inside your Terminal.md
	renamed:    20140603 App Grid Is A Superior Ubuntu Software Center Alternative.md -> 201406/20140603 App Grid Is A Superior Ubuntu Software Center Alternative.md
	renamed:    20140603 Linux Foundation to donate portion of membership fees to Code.org.md -> 201406/20140603 Linux Foundation to donate portion of membership fees to Code.org.md
	renamed:    20140603 Write your first Linux Kernel module.md -> 201406/20140603 Write your first Linux Kernel module.md
	renamed:    20140604 Command line secrets.md -> 201406/20140604 Command line secrets.md
	renamed:    20140604 Setup Virtual Hosts In Apache On Ubuntu 14.04 LTS.md -> 201406/20140604 Setup Virtual Hosts In Apache On Ubuntu 14.04 LTS.md
	renamed:    20140607 Cup 2014 Brazil--Watch FIFA World Cup 2014 Competition in Your Linux Desktop.md -> 201406/20140607 Cup 2014 Brazil--Watch FIFA World Cup 2014 Competition in Your Linux Desktop.md
	renamed:    20140607 How To Extract Images From Videos Using ffmpeg.md -> 201406/20140607 How To Extract Images From Videos Using ffmpeg.md
	renamed:    20140607 How To Install iCup 2014 In Linux.md -> 201406/20140607 How To Install iCup 2014 In Linux.md
	renamed:    20140607 Linux--Bash Delete All Files In Directory Except Few.md -> 201406/20140607 Linux--Bash Delete All Files In Directory Except Few.md
	renamed:    20140607 New OpenSSL breach is no Heartbleed-but needs to be taken seriously.md -> 201406/20140607 New OpenSSL breach is no Heartbleed-but needs to be taken seriously.md
	renamed:    20140607 Nuvola Player 2.4.0 Released -- A Online Cloud Music Player for Linux.md -> 201406/20140607 Nuvola Player 2.4.0 Released -- A Online Cloud Music Player for Linux.md
	renamed:    20140607 Practical Interview Questions and Answers on Linux Shell Scripting.md -> 201406/20140607 Practical Interview Questions and Answers on Linux Shell Scripting.md
	renamed:    20140607 Steam Hits The Big 500 For Linux Games.md -> 201406/20140607 Steam Hits The Big 500 For Linux Games.md
	renamed:    20140607 Ubuntu One Formally Shuts Down.md -> 201406/20140607 Ubuntu One Formally Shuts Down.md
	renamed:    20140609 How To Know If Your System Has USB 3.0 Port In Linux [Quick Tip].md -> 201406/20140609 How To Know If Your System Has USB 3.0 Port In Linux [Quick Tip].md
	renamed:    20140609 Open Source LDAP Solutions.md -> 201406/20140609 Open Source LDAP Solutions.md
	renamed:    "20140609 OpenELEC 4.0.4 \347\216\260\345\267\262\345\217\221\345\270\203, \345\237\272\344\272\216 XBMC 13.1 \342\200\234Gotham\342\200\235.md" -> "201406/20140609 OpenELEC 4.0.4 \347\216\260\345\267\262\345\217\221\345\270\203, \345\237\272\344\272\216 XBMC 13.1 \342\200\234Gotham\342\200\235.md"
	renamed:    20140610 How to set up Internet connection sharing with iptables on Linux.md -> 201406/20140610 How to set up Internet connection sharing with iptables on Linux.md
	renamed:    20140610 IPFire 2.13 Core 78 Linux Firewall OS Receives OpenSSL Fixes.md -> 201406/20140610 IPFire 2.13 Core 78 Linux Firewall OS Receives OpenSSL Fixes.md
	renamed:    20140610 Open Source SDN Project OpenDaylight Adds New Members.md -> 201406/20140610 Open Source SDN Project OpenDaylight Adds New Members.md
	renamed:    20140610 Top 7 Desktop Environment For Linux.md -> 201406/20140610 Top 7 Desktop Environment For Linux.md
	renamed:    20140611 HTG Explains--What' s the Difference Between Linux and BSD.md -> 201406/20140611 HTG Explains--What' s the Difference Between Linux and BSD.md
	renamed:    20140611 How to Prevent Other Users From Accessing Your Home Directory in Ubuntu 14.04.md -> 201406/20140611 How to Prevent Other Users From Accessing Your Home Directory in Ubuntu 14.04.md
	renamed:    20140612 Command Line Tuesdays--Part One.md -> 201406/20140612 Command Line Tuesdays--Part One.md
	renamed:    20140612 Dpkg Vulnerabilities Closed in Ubuntu 14.04.md -> 201406/20140612 Dpkg Vulnerabilities Closed in Ubuntu 14.04.md
	renamed:    20140616 How To Install Numix Icon Theme In Fedora 20.md -> 201406/20140616 How To Install Numix Icon Theme In Fedora 20.md
	renamed:    20140616 Ubuntu Desktop Next 14.10 Images Available to Download.md -> 201406/20140616 Ubuntu Desktop Next 14.10 Images Available to Download.md
	renamed:    20140616 Ubuntu for Phones Activated on 10,000 Devices.md -> 201406/20140616 Ubuntu for Phones Activated on 10,000 Devices.md
	renamed:    20140617 14 Apps To Boost Ubuntu.md -> 201406/20140617 14 Apps To Boost Ubuntu.md
	renamed:    20140619 Improve Battery Life with Laptop Mode Tools 1.65.md -> 201406/20140619 Improve Battery Life with Laptop Mode Tools 1.65.md
	renamed:    20140619 Red Hat to Acquire eNovance, Focus Together on OpenStack.md -> 201406/20140619 Red Hat to Acquire eNovance, Focus Together on OpenStack.md
	renamed:    20140620 Celebrating 30 Years of X.md -> 201406/20140620 Celebrating 30 Years of X.md
	renamed:    20140620 ENCRYPT DNS TRAFFIC IN LINUX WITH DNSCRYPT (VIA OPENDNS).md -> 201406/20140620 ENCRYPT DNS TRAFFIC IN LINUX WITH DNSCRYPT (VIA OPENDNS).md
	renamed:    20140620 How to enable testing and unstable repository on Debian.md -> 201406/20140620 How to enable testing and unstable repository on Debian.md
	renamed:    20140625 Canonical Debuts 'Orange Box' for Ubuntu OpenStack Cloud Demos.md -> 201406/20140625 Canonical Debuts 'Orange Box' for Ubuntu OpenStack Cloud Demos.md
	renamed:    8 examples of findmnt command to check mounted file systems on Linux.md -> 201406/8 examples of findmnt command to check mounted file systems on Linux.md
	renamed:    Bash Getopts--Scripts with Command Line Options.md -> 201406/Bash Getopts--Scripts with Command Line Options.md
	renamed:    Collectl--An Advanced All-in-One Performance Monitoring Tool for Linux.md -> 201406/Collectl--An Advanced All-in-One Performance Monitoring Tool for Linux.md
	renamed:    Fix Adobe Flash Player Issue In Chromium In Ubuntu 14.04.md -> 201406/Fix Adobe Flash Player Issue In Chromium In Ubuntu 14.04.md
	renamed:    Guide To Install Ubuntu 14.04 In Dual Boot Mode With Windows 8 Or 8.1 UEFI.md -> 201406/Guide To Install Ubuntu 14.04 In Dual Boot Mode With Windows 8 Or 8.1 UEFI.md
	renamed:    How To Install 'California' Calendar App in Ubuntu 14.04.md -> 201406/How To Install 'California' Calendar App in Ubuntu 14.04.md
	renamed:    How To Remove Drive Icons From Unity Launcher In Ubuntu 14.04 [Beginner Tips].md -> 201406/How To Remove Drive Icons From Unity Launcher In Ubuntu 14.04 [Beginner Tips].md
	renamed:    How to Install Windows 8.1 and Ubuntu 14.04 LTS on the Same Computer.md -> 201406/How to Install Windows 8.1 and Ubuntu 14.04 LTS on the Same Computer.md
	renamed:    How to download webcomics from the command line on Linux.md -> 201406/How to download webcomics from the command line on Linux.md
	renamed:    How to launch applications differently with Gnome-Pie on Linux desktop.md -> 201406/How to launch applications differently with Gnome-Pie on Linux desktop.md
	renamed:    How to manage Linux containers with Docker on Ubuntu.md -> 201406/How to manage Linux containers with Docker on Ubuntu.md
	renamed:    How to manage ip addresses and subnets with phpIPAM.md -> 201406/How to manage ip addresses and subnets with phpIPAM.md
	renamed:    How to manage passwords from the command line on Linux.md -> 201406/How to manage passwords from the command line on Linux.md
	renamed:    How to monitor Nginx web server from the command line in real time.md -> 201406/How to monitor Nginx web server from the command line in real time.md
	renamed:    How to set up a web-based lightweight system monitor on Linux.md -> 201406/How to set up a web-based lightweight system monitor on Linux.md
	renamed:    How to take a screenshot from the command line on Linux.md -> 201406/How to take a screenshot from the command line on Linux.md
	renamed:    How to take full length screenshots of websites via terminal.md -> 201406/How to take full length screenshots of websites via terminal.md
	renamed:    How to use LVM in Linux.md -> 201406/How to use LVM in Linux.md
	renamed:    How to verify DDOS attack with netstat command on Linux Terminal.md -> 201406/How to verify DDOS attack with netstat command on Linux Terminal.md
	renamed:    Install SoundCloud In Ubuntu 14.04.md -> 201406/Install SoundCloud In Ubuntu 14.04.md
	renamed:    Linux Pros' Top Command Line Secrets.md -> 201406/Linux Pros' Top Command Line Secrets.md
	renamed:    Linux Terminal--Dstat monitoring tools.md -> 201406/Linux Terminal--Dstat monitoring tools.md
	renamed:    Making Linux Feel at Home.md -> 201406/Making Linux Feel at Home.md
	renamed:    Open Source's Cult Of Personality Is Dying--Thankfully.md -> 201406/Open Source's Cult Of Personality Is Dying--Thankfully.md
	renamed:    Pros' Secrets and Red Hat 7 and PCLinuxOS 2014.05 Reviews.md -> 201406/Pros' Secrets and Red Hat 7 and PCLinuxOS 2014.05 Reviews.md
	renamed:    Start Practising Linux ip command and Avoid the Habit of Using ifconfig.md -> 201406/Start Practising Linux ip command and Avoid the Habit of Using ifconfig.md
	renamed:    TechView--Linus Torvalds Inventor of Linux.md -> 201406/TechView--Linus Torvalds Inventor of Linux.md
	renamed:    Turn Off Bluetooth By Default In Ubuntu 14.04 [Quick Tip].md -> 201406/Turn Off Bluetooth By Default In Ubuntu 14.04 [Quick Tip].md
	renamed:    Ubuntu Linux Community Manager Jono Bacon Leaves Canonical.md -> 201406/Ubuntu Linux Community Manager Jono Bacon Leaves Canonical.md
	renamed:    What Heartbleed Teaches Us--Be An Open Source Contributor, Not Just A User.md -> 201406/What Heartbleed Teaches Us--Be An Open Source Contributor, Not Just A User.md
	renamed:    Why htop Command Compete Linux top Command.md -> 201406/Why htop Command Compete Linux top Command.md
2014-06-30 21:53:24 +08:00

122 lines
5.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

如何在Linux上使用命令行管理密码
================================================================================
在基于密码的认证在网络盛行的今天,你可能需要或者已经使用了某种密码管理工具来跟踪管理你正在使用的所有密码。有各种各样的在线或离线服务或者软件工具用于完成此类事情,而这些工具因复杂程度、用户界面或者目标环境(如企业或终端用户)的不同而各不相同。例如,有一些是为终端用户开发基于图形化的密码管理器,如[KeePass(X)][1]。
对于那些不想要依赖图形化进行密码管理的用户,笔者将会讲述如何在命令行下使用 [pass][2]来管理密码,**这是一个简单的用于命令行管理密码的工具**。
该密码工具实际上是一个shell脚本编写的前端其中调用了几个其它工具如gpgpwgengitxsel来使用OpenGPG管理用户的密码信息。各个密码使用gpg工具进行加密并存储到本地密码仓库中。密码信息可以通过终端或者自清除的剪贴板工具使用。
该密码工具相当灵活并且使用起来及其简单。你可以将每个密码信息存储到一个OpenGPG保护的普通文本文件并且将不同的密码文件分组多个类目中。它支持bash自动补全特性因此可以很方便地使用TAB键来补全命令或者很长的密码名称。
### 在Linux上安装pass ###
在DebianUbuntu或者Linux Mint上安装pass
$ sudo apt-get install pass
$ echo "source /etc/bash_completion.d/password-store" >> ~/.bashrc
在Fedora上安装pass
$ sudo yum install pass
$ echo "source /etc/bash_completion.d/password-store" >> ~/.bashrc
在CentOS上安装pass首先[启用EPEL仓库][3],然后执行以下命令:
$ sudo yum install pass
$ echo "source /etc/bash_completion.d/password-store" >> ~/.bashrc
在Archlinux上安装pass
$ sudo pac -S pass
$ echo "source /etc/bash_completion.d/password-store" >> ~/.bashrc
### 初始化本地密码仓库 ###
在使用密码工具之前你需要执行一次初始化步骤该步骤包括创建一个GPG密钥对如果你还没有以及一个本地密码仓库。
首先通过以下步骤创建一个GPG密钥对公钥/私钥。如果已经创建了自己的GPG密钥对可以跳过此步骤。
$ gpg --gen-key
执行该步骤,会询问你如下问题。如果你不确定,可以选择接受默认回答。作为密钥生成部分,你将要为你的密钥创建一个加密口令,这个口令实际上是你访问存储在本地密码仓库中的任何密码信息时的主密码。成功创建密钥对后,创建的密钥对会存储在~/.gnupg目录中。
![](https://farm3.staticflickr.com/2922/13965806430_a19596da60_z.jpg)
接下来,运行以下命令来初始化本地密码仓库。下面的<gpg-id>,输入之前创建密钥对时的关联电子邮件地址。
$ pass init <gpg-id>
该命令会在~/.password-store目录中创建一个密码仓库。
### 在终端使用pass管理密码 ###
#### 插入新密码信息 ####
要将新的密码信息插入到本地密码仓库中,请遵循以下命令格式:
$ pass insert <password-name>
<password-name>是你定义的专有名称,并且可以分级(如 "finance/tdbank", "online/gmail.com")。在这种情况下,密码信息可以存储到~/.password-store目录下对应的子目录中。
如果你想要分多行插入密码信息,请像以下命令一样使用"-m"选项。以你自己喜欢的任何格式来输入密码信息然后按Ctrl+D来结束。
$ pass insert <password-name> -m
![](https://c2.staticflickr.com/6/5564/14129264286_9fc2938c0b_z.jpg)
#### 查看所有密码名称列表 ####
要查看所有存储的密码名称列表,只需输入"pass"命令:
$ pass
![](https://farm3.staticflickr.com/2905/13965804498_92b0af83cf_o.jpg)
#### 从密码仓库中取回密码信息 ####
要访问特定密码列表中的内容,只需使用以下命令:
$ pass <password-name>
例如:
$ pass email/gmail.com
会要求你输入密码口令来解锁密钥。
如果你想要将密码复制到剪贴板,而不是显示到终端屏幕上,使用以下命令:
$ pass -c email/gmail.com
当密码被复制到剪贴板剪贴板在45秒后会被自动清空。
#### 在密码仓库中生成并存储新密码 ####
使用`pass`命令你也可以生成一个新的随机密码该密码可用于任何目的。pass工具将会使用pwgen工具来生成一个好的随机密码。你可以指定密码的长度或者生成带或不带符号的密码。
例如要生成一个具有10个字符不带符号的密码并将它存储到 "email/new_service.com"列表中:
$ pass generate email/new_service.com 10 -n
#### 移除密码信息 ####
要移除现存的密码信息是很容易的:
$ pass rm email/gmail.com
小结一下pass是及其灵活便于携带并且更为重要的是易于使用。对于正在寻找能简单而行之有效地、安全地、并且不依赖图形化管理任何私人信息的工具的人笔者强烈推荐pass。
--------------------------------------------------------------------------------
via: http://xmodulo.com/2014/05/manage-passwords-command-line-linux.html
译者:[GOLinux](https://github.com/译者ID) 校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
[1]:http://xmodulo.com/2013/08/how-to-manage-multiple-passwords-on-linux.html
[2]:http://www.zx2c4.com/projects/password-store/
[3]:http://xmodulo.com/2013/03/how-to-set-up-epel-repository-on-centos.html