首页 > 代码库 > 批量分发
批量分发
ssh两种用法
- 远程连接主机
- 不连接过去,只是执行命令
ssh用法:
-p加端口,默认22可以省略
@前面为用户名,不指定为当前用户
@后面为要连接的服务器的IP
(1)[root@backup .ssh]# ssh -p21987 hp@10.69.112.78
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.
hp@10.69.112.78‘s password:
Last login: Wed Oct 19 16:18:44 2016 from 10.69.112.77
(2)[root@backup ~]# ssh -p21987 hp@10.69.112.78 /sbin/ifconfig eth2
hp@10.69.112.78‘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 user@ip
2 到其他机器上执行命令(不会切到机器上)ssh -p21987 user@ip 命令(全路径)
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/ hp@10.69.112.78:/tmp/
-r 递归
-p保持属性
rsync -avz -e ‘ssh -p 21987‘ /etc hp@10.69.112.78:/tmp
批量分发
[root@backup tmp]# sftp -oPort=21987 hp@10.69.112.78
Connecting to 10.69.112.78...
hp@10.69.112.78‘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
[root@nfs-server ~]# useradd oldboy
[root@nfs-server ~]# echo centos | passwd --stdin oldgirl
[root@nfs-server ~]# echo centos | passwd --stdin oldboy
[root@nfs-server ~]# 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 root@nfs-server
The key‘s randomart image is:
+--[ DSA 1024]----+
| o=+.... . B.|
| oo .o o o B|
| .. . . . ..|
| o.. .|
| . .S. E|
| o. |
| ... |
| . . |
| .. |
+-----------------+
[root@nfs-server ~]# ssh-copy-id -i .ssh/id_dsa.pub "-p 21987 oldboy@10.69.112.133"
[root@nfs-server ~]# scp -P21987 /etc/hosts oldboy@10.69.112.133:~hosts
批量分发
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。