Run the sudo privilege escalation script on the remote server by using ssh.

Source: Internet
Author: User
Executing the script that requires sudo privilege escalation on the remote server through ssh is a magical task. the powerful O & M can easily handle complicated tasks, the Daily O & M time of sb may not be able to solve the problem (ps: because he spent all his time on repetitive tasks) www.2cto. c... executing the script that requires sudo privilege escalation on the remote server using ssh. the O & M is a magical task. the powerful O & M can easily handle complicated tasks, and the O & M of sb consumes a lot of time every day.
I may not be able to solve the problem (ps: because he spent all his time on repetitive tasks). before writing this blog at www.2cto.com, I google a bunch of related articles, most of them are modifying/etc/sudoers, and then NOPASSWD:
The specified cmd does not work. if you do not have a remote virtual terminal, the method is cloud migration. ubuntu10.04 server is tested !! Run the following command in the format of [html] ssh-p $ port $ user @ $ p 'cmd' $ port: ssh connection port number $ user: ssh connection username $ ip: ssh-connected IP address cmd: The operation preparation required for the remote server is based on public/private key authentication or user name/password authentication to ensure that you log on to the remote local2 server (a person with basic O & M knowledge ).
This is not a problem. if it is a script, pay attention to the absolute path problem (the relative path is a pitfall in remote execution). This command can meet most of our needs, however, the root permission is usually required for O & M and deployment of many things,
However, there are several restrictions: remote server local2 prohibits the root user from logging on to the remote server. in the remote server script, the sender password is required for converting the identity using the login Ct, this is not safe enough to execute the script ssh-t parameter [html]-t Force pseudo-tty allocation that requires sudo permission on the remote server. 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. you can provide a remote server virtual tty terminal. with this parameter, you can
Enter your authorization password on the virtual terminal of the server, [html] ssh-t-p $ port $ user @ $ ip 'cmd' sample script [html] #! /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" # run the remote server script www.2cto.com 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 is easy to remember, -t virtualize a remote server terminal, which saves a lot of time when multiple servers are deployed at the same time!
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.