In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.