批量分发
Posted 人生苦短,我用python
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了批量分发相关的知识,希望对你有一定的参考价值。
ssh两种用法
- 远程连接主机
- 不连接过去,只是执行命令
ssh用法:
-p加端口,默认22可以省略
@前面为用户名,不指定为当前用户
@后面为要连接的服务器的IP
(1)[[email protected] .ssh]# ssh -p21987 [email protected]
The authenticity of host ‘[10.69.112.78]:21987 ([10.69.112.78]:21987)‘ can‘t be established.
RSA key fingerprint is ae:b5:46:d4:ef:f0:82:3d:ab:0d:dd:59:9c:70:38:92.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘[10.69.112.78]:21987‘ (RSA) to the list of known hosts.
[email protected]‘s password:
Last login: Wed Oct 19 16:18:44 2016 from 10.69.112.77
(2)[[email protected] ~]# ssh -p21987 [email protected] /sbin/ifconfig eth2
[email protected]‘s password:
eth2 Link encap:Ethernet HWaddr 92:D5:6C:92:BA:C0
inet addr:10.69.112.78 Bcast:10.69.112.255 Mask:255.255.255.0
inet6 addr: fe80::90d5:6cff:fe92:bac0/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:234774 errors:0 dropped:0 overruns:0 frame:0
TX packets:196553 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:27878853 (26.5 MiB) TX bytes:15731641 (15.0 MiB)
ssh小结
1 切换到别的机器上 ssh -p21987 [email protected]
2 到其他机器上执行命令(不会切到机器上)ssh -p21987 [email protected] 命令(全路径)
3 当第一次ssh连接的时候,本地会产生一个密钥文件~/.ssh/known_hosts
ssh配置文件优化:
Port 21987
Protocol 2
SyslogFacility AUTHPRIV
PermitRootLogin no
PasswordAuthentication yes
ChallengeResponseAuthentication no
GSSAPIAuthentication no
GSSAPICleanupCredentials yes
UsePAM yes
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
AcceptEnv XMODIFIERS
X11Forwarding yes
UseDNS no
Subsystem sftp /usr/libexec/openssh/sftp-server
scp -P21987 -r -p /etc/ [email protected]:/tmp/
-r 递归
-p保持属性
rsync -avz -e ‘ssh -p 21987‘ /etc [email protected]:/tmp
批量分发
[[email protected] tmp]# sftp -oPort=21987 [email protected]
Connecting to 10.69.112.78...
[email protected]‘s password:
sftp> put /etc/passwd
Uploading /etc/passwd to /home/hp/passwd
/etc/passwd 100% 1072 1.1KB/s 00:00
scp小结:
1 scp是加密的远程拷贝,而cp仅为本地拷贝
2 可以把数据从一台机器推送到另一台机器,也可以从其他服务器把数据拉回来
3 每次都是全量完整拷贝,效率不高,适合第一次拷贝,如果需要增量拷贝,用rsync
[[email protected] ~]# useradd oldboy
[[email protected] ~]# echo centos | passwd --stdin oldgirl
[[email protected] ~]# echo centos | passwd --stdin oldboy
[[email protected] ~]# ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/root/.ssh/id_dsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_dsa.
Your public key has been saved in /root/.ssh/id_dsa.pub.
The key fingerprint is:
eb:07:16:62:44:c6:e1:d7:00:5d:9d:d7:31:f3:31:fe [email protected]
The key‘s randomart image is:
+--[ DSA 1024]----+
| o=+.... . B.|
| oo .o o o B|
| .. . . . ..|
| o.. .|
| . .S. E|
| o. |
| ... |
| . . |
| .. |
+-----------------+
[[email protected] ~]# ssh-copy-id -i .ssh/id_dsa.pub "-p 21987 [email protected]"
[[email protected] ~]# scp -P21987 /etc/hosts [email protected]:~hosts
以上是关于批量分发的主要内容,如果未能解决你的问题,请参考以下文章