gpg openssl ssh scp rsync sftp Pssh、pslurp、pscp.pssh工具 ...
gpg
gpg---OpenPGP encryption and signing tool
gpg [options] [files]
-c, --symmetric 僅使用對稱加密
-e, --encrypt 加密數據
-d, --decrypt 解密數據
-s, --sign 製作簽名
--clearsign 製作一個清晰文本簽名
--verify 檢查簽名
-o, --output FILE 寫出到文件
--gen-key 生成一個新的密鑰對
-k, --list-keys 列出密鑰
--export 導出密鑰
--import 導入或合併密鑰
-a, --armor create ascii armored()output
-r, --recipient USER-ID 為用戶id加密
--delete-keys 移除公鑰
--delete-secret-keys 移除私鑰
來自包:
rpm -q --whatprovides gpg
gnupg2-2.0.14-8.el6.x86_64
包內文件:
rpm -ql gnupg2
示例:
1.對稱加密file 文件
在A主機上加密file
gpg -c file
ls file.gpg
在B主機上解密file
gpg -o file -d file.gpg
2.非對稱(公鑰)加密file文件
在hostB 主機上用公鑰加密,在hostA 主機上解密。
在hostA 主機上生成公鑰/私鑰對
gpg --gen-key
在hostA 主機上查看公鑰
gpg --list-keys
在hostA 主機上導出公鑰到wang.pubkey
gpg -a --export -o wang.pubkey
從hostA 主機上複製公鑰文件到需加密的B 主機上
scp wang.pubkey hostB:
在需加密數據的hostB 主機上生成公鑰/私鑰對
gpg --gen-key
在hostB 主機上導入公鑰
gpg --import wang.pubkey
gpg --list-keys
用從hostA 主機導入的公鑰,加密hostB 主機的文件file, 生成file.gpg
gpg -e -r wangxiaochun file
file file.gpg
複製加密文件到hostA 主機
scp fstab.gpg hostA:
在hostA 主機解密文件
gpg -d file.gpg
gpg -o file -d file.gpg
刪除公鑰和私鑰
gpg --delete-keys wangxiaochun
gpg --delete-secret-keys wangxiaochun
openssl
openssl - OpenSSL command line tool(openssl命令行工具)
openssl command [ command_opts ] [ command_args ]
openssl [ list-standard-commands | list-message-digest-commands | list-cipher-commands | list-cipher-algorithms | list-message-digest-algorithms | list-public-key-algorithms]
openssl no-XXX [ arbitrary options ]:判斷XXX命是否存在
openssl ?打開command列表
1)openssl enc命令
對稱加密
幫助:man enc
enc - symmetric(對稱的)cipher(密碼)routine(程式)
對稱密碼命令支持數據使用各種塊(填充物)加密或解密。
openssl enc -ciphername
[-in filename]:導入文件
[-out filename]:導出文件
[-pass arg]:傳遞密碼源
[-e]:加密
[-d]:解密
[-a/-base64]:基於base64的加密
[-A]:有-a時,base64在一行上處理數據
[-k password]:密碼源於key
[-kfile filename]
[-K/-iv key/IV]:key/lv 採用十六進位,是下個密碼
[-S salt]:採用十六進位的salt,是下個密碼
[-salt]:使用salt(隨機)
[-nosalt]:不使用salt
[-z]:在加密或解密前進行壓縮或解壓縮文本
[-md]:用於從密碼上創建key
[-p]:列印使用的key和IV
[-P]:列印使用的key和IV,且馬上退出而不進行加密或解密
[-bufsize number]:為I/O設置buffer 尺寸
加密:
openssl enc -e -des3 -a -salt -in testfile -out testfile.cipher
解密:
openssl enc -d -des3 -a -salt -in testfile.cipher -out testfile
2)openssl dgst
單向加密
幫助:man dgst
dgst, md5, md4, md2, sha1, sha, mdc2, ripemd160 - message digests(信息摘要)(hash(data)=digest 摘要)
digist的功能是輸出所支持文件或十六進位形式文件的摘要信息,同樣可用於數字簽名和核查
openssl dgst [-md5|-md4|-md2|-sha1|-sha|-mdc2|-ripemd160|-dss1]: [file...]
[-c]:輸出以冒號為分割符的兩位數
[-d]:列印BIO的調試信息
[-hex]:採用16進位輸出(預設輸出)
[-binary]:採用二進位輸出
[-out filename]:輸出到文件或標準輸出
[-sign filename]:在文件中使用私鑰來簽名
[-keyform arg]:指定key形式來簽名
[-passin arg]:私鑰源
[-verify filename]:使用文件中公鑰核查簽名
[-prverify filename]:使用文件中的私鑰來核查簽名
[-signature filename]:核查實際的簽名
[-hmac key]:使用key來創建hashed MAC
openssl dgst -md5 [-hex 預設] /PATH/SOMEFILE
openssl dgst -md5 testfile
md5sum /PATH/TO/SOMEFIL
3)openssl passwd
生成密碼
幫助:man sslpasswd
passwd - compute password hashes(計算密碼散列)
用於計算工作狀態下輸入密碼的散列或是列表的中密碼的散列
openssl passwd [-crypt]:標準的Unix密碼演算法(預設) [password]
[-1]:基於MD5的密碼演算法
[-apr1]:基於md5的密碼演算法,Apache不同
[-salt string]:使用所提供的salt
[-in file]:從文件中讀取密碼
[-stdin]:從標準輸入中讀取密碼
[-noverify]:從終端讀取密碼時不進行檢查
[-quiet]:不要警告
[-table]:表格格式輸出
[--reverse]:轉換表列
openssl passwd -1 -salt SALT( 最多8 位)
openssl passwd -1 –salt centos
4)openssl rand
生成隨機數
幫助:man sslrand
rand - generate pseudo-random bytes(生成偽隨機碼)
rand命令一旦種植了隨機數生成器後就輸出虛隨機碼位的數字
openssl rand [-out file]:寫到文件 num
[-rand file(s)]:從文件中播種下PRNG
[-base64]:base64編碼輸出
[-hex]:十六進位編碼輸出
openssl rand -base64|-hex NUM
NUM:表示位元組數;-hex時,每個字元為十六進位,相當於4 位二進位,出現的字元數為NUM*2
5)openssl rsautl
公鑰加密(非對稱加密)
幫助:man rsautl
rsautl - RSA utility(RSA功用)
rsautl 命令使用RSA演算法用於簽名,檢測,加密和解密數據。
openssl rsautl [-in file]:輸入文件
[-out file]:輸出到文件
[-inkey file]:輸入key
[-pubin]:輸入是個RSA 公鑰
[-certin]:輸入是個含有RSA公鑰的證書
[-sign]:簽名輸入數據,輸出簽名結果,要求有RSA私鑰
[-verify]:核查輸入數據和輸出的恢複數據
[-encrypt]:使用RSA公鑰加密輸入數據
[-decrypt]:使用RSA私鑰加密輸入數據
[-pkcs] [-ssl] [-raw]
[-hexdump]:十六進位輸出
[-asn1parse]:
6)openssl genrsa
生成私鑰
幫助:man genrsa
genrsa - generate an RSA private key(產生RSA私鑰)
genrsa 命令生成一個RSA私鑰
openssl genrsa [-out filename]:輸出到文件,若沒指定則標準輸出
[-passout arg]:輸出文件密碼源
[-des][-des3][-idea]:使用加密演算法對產生的密鑰進行加密
[-f4][-3]:使用公共說明,或65537或3,預設65537。
[-rand file(s)]:載入文件到隨機數生成器中
[-engine id]:指定engine
[numbits]:指定私鑰的bit位,預設位512,必須放到最後指定
示例:
生成私鑰
openssl genrsa -out /PATH/TO/PRIVATEKEY.FILE [numbits]
chmod +600 privatekey.file
or
(umask 077(用於修改許可權); openssl genrsa –out test.key –des 2048)(括弧用進行子進程,使得umask隻影響子進程)
7)openssl rsa
從私鑰中提取
幫助:man rsa
rsa - RSA key processing tool(RSA密鑰處理工具)
rsa命令處理RSA密鑰,可使密鑰在各種格式下轉換並且進行內容輸出
openssl rsa [-inform PEM|NET|DER]:輸入形式
[-outform PEM|NET|DER]:輸出形式
[-in filename]:輸入文件
[-passin arg]:輸入文件密碼源
[-out filename]:輸出文件
[-passout arg]:輸出文件密碼源
[-sgckey]:使用IIS SGC 密鑰a.形式
[-des][-des3][-idea][-seed]:加密形式
[-text]:採用text列印密鑰
[-noout]:不列印出密鑰
[-modulus]:列印RSA密鑰模數
[-check]:檢查密鑰一致性
[-pubin]:預設是從文件讀取私鑰,使用這個選項就是讀取公鑰
[-pubout]:預設是輸出私鑰,使用這個選項就輸出公鑰
[-engine id]:指定engine ID
示例:
從私鑰中提取公鑰
openssl rsa -in private key file –pubout –out publickey file
openssl rsa –in test.key –pubout –out test.key.pub
openssl rsa -in key.pem -text -noout
openssl rsa -in key.pem -outform DER -out keyout.der
openssl rsa -in key.pem -des3 -out keyout.pem
openssl rsa -in key.pem -out keyout.pem
8)openssl req
證書申請
幫助:man req
req - PKCS#10 certificate request and certificate generating utility.(證書請求和證書產生功用)
自簽名證書req命令主要是採用PKCS#10格式創建和處理證書請求。它可以為根CA創建自簽名證書。
openssl req [-inform PEM|DER]:指定輸入格式,預設為PEM格式
[-outform PEM|DER]:指定輸出格式
[-in filename]:指定讀取請求所需的文件。若未指定則使用標準輸入
[-passin arg]:輸入文件密碼源
[-out filename]:證書輸出到文件
[-passout arg]:輸出文件密碼源
[-text]:採用text格式列印出證書請求
[-pubkey]:輸出公鑰
[-noout]:阻止輸出請求的加密譯文
[-verify]:核查請求上的簽名
[-modulus]:列印出包含在請求中的公鑰模數值
[-new]:生成新證書簽署請求
[-rand file(s)]:使用包含隨機數的文件來產生隨機數
[-newkey rsa:bits|alg:file]:創建一個新的證書請求和一個私鑰
[-nodes]:
[-key filename]:生成請求是用到的私鑰文件
[-keyform PEM|DER]:指定私鑰文件的格式
[-keyout filename]:輸出新創建的私鑰到文件
[-keygen_engine id]:
[-[digest]]:指定簽名請求時使用的message digest
[-config filename]:指定可供選擇的配置文件
[-subj arg]:
[-multivalue-rdn]
[-x509]:專用於CA生成自簽名證書
[-days n]:證書的有效期限,預設為30天
[-set_serial n]
[-asn1-kludge]
[-no-asn1-kludge]
[-newhdr]
[-extensions section]
[-reqexts section]
[-utf8]
[-nameopt]
[-reqopt]
[-subject]
[-subj arg]
[-batch]:不使用交換模式
[-verbose]:輸出詳細操作信息
[-engine id]:
示例:
openssl req -new -x509 –key /etc/pki/CA/private/cakey.pem -days 7300 -out /etc/pki/CA/cacert.pem
openssl req -new -key /etc/pki/tls/private/test.key -days 365 -out /etc/pki/tls/test.csr
openssl req -new -key /etc/pki/CA/private/cakey.pem -out /etc/pki/tls/testsubca.csr
openssl req -in req.pem -text -verify -noout
openssl genrsa -out key.pem 1024
openssl req -new -key key.pem -out req.pem
openssl req -newkey rsa:1024 -keyout key.pem -out req.pem
openssl req -x509 -newkey rsa:1024 -keyout key.pem -out req.pem
9)openssl ca
幫助:man ca
ca - sample minimal CA application(CA應用)
ca命令是個最低等級的CA應用,
openssl ca [-verbose]
[-config filename]
[-name section]
[-gencrl]:基於index文件中信息,產生一個CRL
[-revoke file]:撤回證書文件
[-crl_reason reason]
[-crl_hold instruction]
[-crl_compromise time]
[-crl_CA_compromise time]
[-crldays days]
[-crlhours hours]
[-crlexts section]
[-startdate date]
[-enddate date]
[-days arg]
[-md arg]
[-policy arg]
[-keyfile arg]
[-key arg]
[-passin arg]
[-cert file]
[-selfsign]
[-in file]:輸入PEM編碼證書請求
[-out file]:輸出證書
[-notext]
[-outdir dir]
[-infiles]
[-spkac file]
[-ss_cert file]
[-preserveDN]
[-noemailDN]
[-batch]
[-msie_hack]
[-extensions section]
[-extfile section]
[-engine id]
[-subj arg]
[-utf8]
[-multivalue-rdn]
[status serial]:根據編號碼顯示證書狀態
示例:
openssl ca -in req.pem -out newcert.pem
openssl ca -in req.pem -extensions v3_ca -out newcert.pem
openssl ca -gencrl -out crl.pem
openssl ca -infiles req1.pem req2.pem req3.pem
openssl ca -spkac spkac.txt
文件:
/usr/local/ssl/lib/openssl.cnf - master configuration file
./demoCA - main CA directory
./demoCA/cacert.pem - CA certificate
./demoCA/private/cakey.pem - CA private key
./demoCA/serial - CA serial number file
./demoCA/serial.old - CA serial number backup file
./demoCA/index.txt - CA text database file
./demoCA/index.txt.old - CA text database backup file
./demoCA/certs - certificate output file
./demoCA/.rnd - CA random seed information
10)openssl crl
幫助:man crl
crl - CRL utility
crl命令採用DER或者PEM格式處理CRL文件
openssl crl [-inform PEM|DER]
[-outform PEM|DER]
[-text]:以text格式列印輸出CRL
[-in filename]
[-out filename]
[-noout]:不輸出加密版的CRL
[-hash]
[-issuer]
[-lastupdate]
[-nextupdate]
[-CAfile file]
[-CApath dir]
示例:
openssl crl -in crl.pem -outform DER -out crl.der
openssl crl -in crl.der -text -noout
ssh
ssh - OpenSSH SSH client (remote login program)
ssh [user@]host [COMMAND]
ssh [-1246AaCfgKkMNnqsTtVvXxYy] [user@]hostname [command]
[-b bind_address]
[-c cipher_spec]
[-D [bind_address:]port]
[-e escape_char]
[-F configfile]
[-I pkcs11]
[-i identity_file]
[-L [bind_address:]port:host:hostport]
[-l login_name]
[-m mac_spec]
[-O ctl_cmd]
[-o option]
[-p port]
[-R [bind_address:]port:host:hostport]
[-S ctl_path]
[-W host:port]
[-w local_tun[:remote_tun]
ssh [-l user] [user@]host [COMMAND]
-p port :遠程伺服器監聽的埠
-b: 指定連接的源IP
-v: 調試模式
-C:壓縮方式
-X: 支持x11 轉發
-Y:支持信任x11 轉發
ForwardX11Trusted yes
-t: 強制偽tty 分配
ssh -t remoteserver1 ssh remoteserver2
scp
scp — secure copy (remote file copy program)
scp [-12346BCpqrv] [[user@]host1:]file1 ... [[user@]host2:]file2
[-c cipher]
[-F ssh_config]
[-i identity_file]
[-l limit]
[-o ssh_option]
[-P port]
[-S program]
scp [options] SRC... DEST/
scp [options] [user@]host : /sourcefile /destpath
scp [options] /sourcefile [user@]host:/destpath
常用選項:
-C: 壓縮數據流
-r: 遞歸複製
-p: 保持原文件的屬性信息
-q: 靜默模式
-P PORT: 指明remote host 的監聽的埠
rsync
基於ssh 和rsh 服務實現高效率的遠程系統之間複製文件
使用安全的shell 連接做為傳輸方式
比scp 更快,只複製不同的文件
rsync - a fast, versatile(通用的), remote and local file-copying tool
Local:
rsync [OPTION...] SRC... [DEST]
Access via remote shell:
Pull: rsync [OPTION...] [USER@]HOST:SRC... [DEST]
Push: rsync [OPTION...] SRC... [USER@]HOST:DEST
Access via rsync daemon:
Pull: rsync [OPTION...] [USER@]HOST::SRC... [DEST]
rsync [OPTION...] rsync://[USER@]HOST[:PORT]/SRC... [DEST]
Push: rsync [OPTION...] SRC... [USER@]HOST::DEST
rsync [OPTION...] SRC... rsync://[USER@]HOST[:PORT]/DEST
rsync –av /etc server1:/tmp 複製目錄和目錄下文件
rsync –av /etc/ server1:/tmp 只複製目錄下文件
選項:
-n 模擬複製過程
-v 顯示詳細過程
-r 遞歸複製目錄樹
-p 保留許可權
-t 保留時間戳
-g 保留組信息
-o 保留所有者信息
-l 將軟鏈接文件本身進行複製(預設)
-L 將軟鏈接文件指向的文件複製
-a 存檔,相當於–rlptgoD ,但不保留ACL (-A )和SELinux 屬性(-X)
sftp
互動式文件傳輸工具
用法和傳統的ftp 工具相似
利用ssh服務實現安全的文件上傳和下載
sftp — secure file transfer program
sftp [-1246aCfpqrv] [-B buffer_size] [-b batchfile] [-c cipher] [-D sftp_server_path] [-F ssh_config][-i identity_file] [-l limit] [-o ssh_option] [-P port] [-R num_requests] [-S program][-s subsystem | sftp_server] host
sftp [user@]host[:file ...]
sftp [user@]host[:dir[/]]
sftp -b batchfile [user@]host
使用ls cd mkdir rmdir pwd get put 等指令, 可用?或help獲取幫助信息
sftp [user@]host
sftp> help
Pssh、pslurp、pscp.pssh工具
/usr/bin/pnuke
/usr/bin/prsync
/usr/bin/pscp.pssh
/usr/bin/pslurp
/usr/bin/pssh
pssh — parallel ssh program
pssh [-I] [-vAiIP][-h hosts_file] [-H [user@]host[:port]] [-l user] [-p par] [-o outdir] [-e errdir] [-t timeout][-O options] [-x args] [-X arg] command ...
pssh是一個python 編寫可以在多台伺服器上執行命令的工具,也可實現文件複製
pssh [OPTIONS] command [...]
--version : 查看版本
-h : 主機文件列表,內容格式”[user@]host[:port]”
-H : 主機字元串,內容格式”[user@]host[:port]”
-l : 登錄使用的用戶名
-p : 併發的線程數 【 可選 】
-o : 輸出的文件目錄 【 可選 】
-e : 錯誤輸入文件 【 可選 】
-t : TIMEOUT 超時時間設置,0 無限制 【 可選 】
-O : SSH 的選項
-v : 詳細模式
-A : 手動輸入密碼模式
-x : 額外的命令行參數使用空白符號,引號,反斜線處理
-X : 額外的命令行參數,單個參數模式,同-x
-i : 每個伺服器內部處理信息輸出
-P : 列印出伺服器返回信息
pslurp:複製遠程文件到本地
pslurp is a program for copying files in parallel from a number of hosts.
pscp.pssh:複製本地文件到遠程主機
pscp.pssh is a program for copying files in parallel to a number of hosts
prsync:複製本地文件到遠程主機
prsync is a program for copying files in parallel to a number of hosts.
pnuke:遠程關閉進程
pnuke is a program for killing processes in parallel on a number of hosts
pslurp [OPTIONS] remote local
pslurp -h hosts.txt -L /tmp/outdir -l irb2 /home/irb2/foo.txt foo.txt
pscp.pssh [OPTIONS] local remote
pscp -h hosts.txt -l irb2 foo.txt /home/irb2/foo.txt
prsync [OPTIONS] local remote
prsync -r -h hosts.txt -l irb2 foo /home/irb2/foo
pnuke [OPTIONS] pattern
pnuke -h hosts.txt -l irb2 java