In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article focuses on "what ssh remote command execution methods and Shell scripts", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn what ssh remote command execution methods and Shell scripts are available.
Ssh performs remote operations
Command format
The code is as follows:
Ssh-p $port $user@$p 'cmd'
$port: ssh connection port number
$user: ssh connection user name
Ip address of $ip:ssh connection
Cmd: actions to be performed by the remote server
Preparatory work
Based on public and private key authentication or user name password authentication can ensure login to the remote local2 server (it is not a problem for people with basic knowledge of operation and maintenance to do this)
If cmd is a script, pay attention to the problem of absolute path (relative path is a pit when executed remotely)
Deficiency
This command can meet most of our needs, but usually when OPS deploys a lot of things, it requires root permission, but there are several restrictions:
Remote server local2 forbids root users from logging in
Changing identities to expect in a remote server script requires a send password, which is not secure enough
-t parameter of ssh
The code is as follows:
-t Force pseudo-tty allocation. This can be used to execute arbitrary screen-based programs on a remote machine, which can be very useful, e.g. When implementing menu services. Multiple-t options force tty allocation, even if ssh has no local tty.
That is, we can provide a virtual tty terminal of a remote server. With this parameter, we can enter our own authorization password on the virtual terminal of the remote server, which is very secure.
Command format
The code is as follows:
Ssh-t-p $port $user@$ip 'cmd'
Sample script
The code is as follows:
#! / bin/bash
# variable definition
Ip_array= ("192.168.1.1"192.168.1.2"192.168.1.3")
User= "test1"
Remote_cmd= "/ home/test/1.sh"
# execute remote server scripts locally through ssh
For ip in ${ip_array [*]}
Do
If [$ip = "192.168.1.1"]; then
Port= "7777"
Else
Port= "22"
Fi
Ssh-t-p $port $user@$ip "remote_cmd"
Done
At this point, I believe you have a deeper understanding of "what ssh remote command execution methods and Shell scripts". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.