相关命令

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
posted @ 2018-02-14 18:44  shenxm  阅读(352)  评论(0编辑  收藏  举报