一.基于口令验证
[root@zyl ~]# cat ~/.ssh/known_hosts
cat: /root/.ssh/known_hosts: No such file or directory
[root@zyl ~]# ls -l ~/ -a
total 14264
dr-xr-x---. 3 root root 4096 Jun 26 19:08 .
dr-xr-xr-x. 32 root root 4096 Jun 28 17:25 ..
drwx-wx-wx. 2 root root 4096 Jun 19 14:06 044dir
-rw--w--w-. 1 root root 0 Jun 19 14:09 044file
-rw-------. 1 root root 1119 Jun 8 19:36 anaconda-ks.cfg
。。。。。。。。。。####没有ssh
[root@zyl ~]# ssh -p22 root@192.168.21.132 ##ssh -p端口号 远程主机用户@远程主机ip
The authenticity of host ‘192.168.21.132 (192.168.21.132)‘ can‘t be established.
RSA key fingerprint is 0d:83:2a:1e:5d:e5:b7:1f:bf:9e:65:45:25:7b:77:59.
Are you sure you want to continue connecting (yes/no)? yes##输入yes
Warning: Permanently added ‘192.168.21.132‘ (RSA) to the list of known hosts.
root@192.168.21.132‘s password: #####密码
Last login: Tue Jun 28 20:14:59 2016 from 192.168.21.1
[root@zyl ~]# logout
Connection to 192.168.21.132 closed. ##远程主机关闭
[root@zyl ~]# cat ~/.ssh/known_hosts ##当前主机
192.168.21.132 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAtyd5b2bSoSmJ1d6cBkPOtFvRP+zbG1/6mC8po13u+o5254TNXwCnmRZqehZJRYLxYaSsKBRpV9ogi+r6JX9KXMO40VUS5cDjVSQ1bxldP3Y4a6WrzvGD/jIsEYHosqYlO19keDC1PKO6UTBlOHdj2tuxmD5DMkk+HHxVaHTt5ZNGBheljpNhiGhbxiCIoPtibSRaeZ7RfxSsr9tk4aANEx46tCzb9ph6WKFjgd+iAphLfxFBfcFh1dk3c7g+Xg8RPKd0jZjwWWESLtfZDtt0tM0xMJXaV0rLolsv5mKjs+HSCBsdZl0jKpktijfW1ZKr4CCBOwwmU7QT9fwSEjp9hQ==
[root@zyl ~]#
二.不登陆远程主机,直接在远程主机执行命令
[root@zyl ~]# ssh -p22 root@192.168.21.132 /sbin/ifconfig
root@192.168.21.132‘s password:
eth0 Link encap:Ethernet HWaddr 00:0C:29:2C:3D:B3
inet addr:192.168.21.132 Bcast:192.168.21.255 Mask:255.255.255.0
三.
(一):1 2####### 拷贝文件
1.推push:
[root@zyl ~]# scp -P22 /oldboy/b.txt root@192.168.21.132:/oldboy
源(本机) 目标(远程服务器)
root@192.168.21.132‘s password:
b.txt 100% 19 0.0KB/s 00:00
[root@zyl ~]#
2.推pull:
[root@zyl ~]# scp -P22 root@192.168.21.132:/oldboy/newfile /oldboy
目标 源
root@192.168.21.132‘s password:
newfile 100% 0 0.0KB/s 00:00
(二)
[root@zyl oldboy]# scp -P22 -r /oldboy/ root@192.168.21.132:/oldboy2 ####### 拷贝目录 参数-r
root@192.168.21.132‘s password:
[root@zyl /]# sftp -oport=22 root@192.168.21.132
Connecting to 192.168.21.132...
root@192.168.21.132‘s password: #######密码
sftp> put a.log ###拷贝文件 sftp拷贝文件用put
Uploading a.log to /root/a.log
a.log 100% 41 0.0KB/s 00:00
sftp>
(三)
客服端上传文件默认是传到服务器家目录
[root@zyl oldboy7]# sftp -oport=22 root@192.168.21.128
Connecting to 192.168.21.128...
root@192.168.21.128‘s password:
sftp> put /oldboy7/oldboy7.txt
Uploading /oldboy7/oldboy7.txt to /root/oldboy7.txt
/oldboy7/oldboy7.txt 100% 12 0.0KB/s 00:00
客服端文件可以上传到服务器指定目录
sftp> put /oldboy7/oldboy7.txt /oldboy7
Uploading /oldboy7/oldboy7.txt to /oldboy7/oldboy7.txt
/oldboy7/oldboy7.txt 100% 12 0.0KB/s 00:00
sftp>
客服端下载服务器上的文件是下载到当前处于当前目录
sftp> get /oldboy8/oldboy8.txt sftp下载文件文件用get
Fetching /oldboy8/oldboy8.txt to oldboy8.txt
sftp> quit
客服端下载服务器上的文件是可以指定下载目录
[root@zyl /]# sftp -oport=22 root@192.168.21.128
Connecting to 192.168.21.128...
root@192.168.21.128‘s password:
sftp> get /oldboy8/oldboy8.txt /oldboy
Fetching /oldboy8/oldboy8.txt to /oldboy/oldboy8.txt
本文出自 “10900500” 博客,请务必保留此出处http://10910500.blog.51cto.com/10900500/1794570
原文地址:http://10910500.blog.51cto.com/10900500/1794570