shell脚本-linux如何在脚本中远程到一台linux机器并执行命令
创始人
2025-01-11 13:35:32
0次

需求:我们需要从11.0.1.17远程到11.0.1.16上执行命令

实现:

1.让11.0.1.17 可以免密登录到11.0.1.16

[root@localhost ~]# ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa):  Created directory '/root/.ssh'. Enter passphrase (empty for no passphrase):  Enter same passphrase again:  Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: SHA256:bu287XmVZ6enpUciggpz71Q7e5kfKYqVMTcM5bDD8eU root@localhost.localdomain The key's randomart image is: +---[RSA 2048]----+ |          o . .  | |         . B o   | |          = o E  | |           +     | |        S.+ +   .| |    o ...o.*...o*| |     + o+ *..+o*+| |      .o.= =+oo+o| |       .o *++o++ | +----[SHA256]-----+  [root@localhost ~]# ssh-copy-id -i .ssh/id_rsa.pub root@11.0.1.16 /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: ".ssh/id_rsa.pub" The authenticity of host '11.0.1.16 (11.0.1.16)' can't be established. ECDSA key fingerprint is SHA256:Zedce2a7sFWF3pYJaVtedqST+SsG1zbPZ7Y4rGiEpB0. ECDSA key fingerprint is MD5:57:75:f6:6f:68:ba:b2:b8:38:0f:55:96:c9:19:d6:29. Are you sure you want to continue connecting (yes/no)? yes /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys root@11.0.1.16's password:   Number of key(s) added: 1  Now try logging into the machine, with:   "ssh 'root@11.0.1.16'" and check to make sure that only the key(s) you wanted were added.   

2.在脚本中实现我们想要的功能

[root@localhost ~]# cat test.sh  #!/bin/bash ssh root@11.0.1.16 <  mtu 1500         inet 11.0.1.16  netmask 255.255.255.0  broadcast 11.0.1.255         inet6 fe80::20c:29ff:fe00:9681  prefixlen 64  scopeid 0x20         ether 00:0c:29:00:96:81  txqueuelen 1000  (Ethernet)         RX packets 95760  bytes 67679836 (64.5 MiB)         RX errors 0  dropped 0  overruns 0  frame 0         TX packets 45061  bytes 3990000 (3.8 MiB)         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0  lo: flags=73  mtu 65536         inet 127.0.0.1  netmask 255.0.0.0         inet6 ::1  prefixlen 128  scopeid 0x10         loop  txqueuelen 1  (Local Loopback)         RX packets 24  bytes 2547 (2.4 KiB)         RX errors 0  dropped 0  overruns 0  frame 0         TX packets 24  bytes 2547 (2.4 KiB)         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0  

相关内容

热门资讯

每日必看!江岸多玩到底能开挂吗... 每日必看!江岸多玩到底能开挂吗(辅助挂),江岸多玩原来真的有辅助挂讲义1、江岸多玩脚本辅助下载、江岸...
玩家交流!颖河竞技怎么开挂(外... 玩家交流!颖河竞技怎么开挂(外挂),颖河竞技好像是有外挂教材一、颖河竞技游戏安装教程牌型概率发牌机制...
最新通报!皮皮四川麻将软件下载... 最新通报!皮皮四川麻将软件下载(辅助挂),皮皮四川麻将果然有辅助挂模块1、操作简单,无需皮皮四川麻将...
一分钟揭秘!52游戏开挂脚本(... 一分钟揭秘!52游戏开挂脚本(透视挂),52游戏切实有透视挂法子52游戏脚本下载中分为三种模型:52...
一分钟快速了解!堆堆乐开挂破解... 一分钟快速了解!堆堆乐开挂破解(外挂),堆堆乐竟然真的有外挂方针1、下载好堆堆乐正确养号方法之后点击...
重大通报!汇城贵州麻将开挂脚本... 重大通报!汇城贵州麻将开挂脚本(开挂),汇城贵州麻将原来真的有开挂法门1、重大通报!汇城贵州麻将开挂...
盘点一款!七色城透视挂件(外挂... 盘点一款!七色城透视挂件(外挂),七色城切实是真的有外挂经验1、全新机制【七色城ai辅助工具激活码】...
今日头条!多多休闲透视软件下载... 今日头条!多多休闲透视软件下载(外挂),多多休闲确实是真的有外挂攻略1、首先打开多多休闲辅助器下载最...
关于!钱柜麻将真的有透视吗(辅... 关于!钱柜麻将真的有透视吗(辅助器),钱柜麻将一贯是有辅助器练习钱柜麻将能透视中分为三种模型:钱柜麻...
今日焦点!河北家乡棋牌辅助工具... 今日焦点!河北家乡棋牌辅助工具(外挂),河北家乡棋牌果然是有外挂手册小薇(辅助器软件下载)致您一封信...