两台linux服务器之间传输数据或执行命令,操作上具体到ssh或linux版本不同可能会有所差异:
1、建立公匙
2、配置公匙,建立信任机制
3、传输文件/数据
4、远程执行命令
公匙产生:
公匙方式一
$ cd ~
$ cd .ssh
$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in .ssh/id_rsa.
Your public key has been saved in .ssh/id_rsa.pub.
The key fingerprint is:
4d:5d:0e:9f:98:b6:56:aa:ce:4b:d3:c3:81:71:88:6a
公匙方式二
$ cd ~/.ssh
$ ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (.ssh/id_dsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in .ssh/id_dsa.
Your public key has been saved in .ssh/id_dsa.pub.
The key fingerprint is:
83:25:2a:e1:de:02:c6:00:ff:50:c2:16:e3:1e:42:b7
$
文件传输:A 192.168.0.2 B 192.168.0.1
设要把 A上的 /root/abc.sh 传到 B机并放到/abc目录,可以在A机上用命令
scp /root/abc.sh
若 SSH端口不是默认的22,比如,是端口1234 则加-P参数:
scp -P 1234 /root/abc.sh
也可以在B机上用命令:
scp /abc/
配置公匙文件:
1.公匙复制 scp ~/.ssh/id_rsa_2.pub
2.公匙配置 cat ~/.ssh/id_rsa_2.pub>>~/.ssh/authorized_keys
以上两步将A的公匙配置到B服务器
B服务器可以直接登录A服务器了
命令执行:
$ ssh -h
ssh: illegal option -- h
usage: ssh [-1246AaCfghkMNnqsTtVvXxY] [-b bind_address] [-c cipher_spec]
[-D port] [-e escape_char] [-F configfile] [-i identity_file]
[-L port:host:hostport] [-l login_name] [-m mac_spec] [-o option]
[-p port] [-R port:host:hostport] [-S ctl] [user@]hostname [command]
例如:从B机器发送命令到A机器
ssh 192.168.0.2 'source ~/.bash_profile; pwd;ls'
以上命令导入机器环境,并显示目前目录和目录下内容
阅读(3174) | 评论(0) | 转发(0) |