Previously, I saw that most of them were modifying/etc/sudoers, and then NOPASSWD: the specified cmd. But I really don't want to use it. If there is no remote virtual terminal, this method is cloud float, and Ubuntu10.04Server is tested !! Ssh-p $ port $ user @ $ p 'cmd' $ port: ssh connection port number $ user: ssh connection username $ ip: ip address of the ssh connection cmd: operations to be executed on the remote server
Previously, I saw that most of them were modifying/etc/sudoers, and then NOPASSWD: the specified cmd. But I really don't want to use it. If there is no remote virtual terminal, this method is cloud float. Ubuntu10.04 Server is tested !!
Ssh remote operation
Command Format
Ssh-p $ port $ user @ $ p 'cmd'
$ Port: ssh connection port number
$ User: ssh connection username
$ Ip: ip address of the ssh connection
Cmd: operations to be performed by the Remote Server
Preparations
Based on public/private key authentication or user name/password authentication, you can log on to the remote local2 server. (this is not a problem if you have basic O & M knowledge)
If it is a script, pay attention to the absolute path problem (the relative path is pitfall during Remote execution)
Insufficient
- This command can meet most of our needs, but usually the root permission is required for O & M to deploy many things, but there are several restrictions:
- Remote Server local2 prevents root User Logon
- In the remote server script, sending a password is required for converting the identity using the login CT, which is not safe enough.
Execute scripts that require sudo permissions on the remote server
-T parameter of ssh
-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.
You can provide a remote server virtual tty terminal. With this parameter, you can enter your authorization password on the remote server virtual terminal, which is very secure.
Command Format
Ssh-t-p $ port $ user @ $ ip 'cmd'
Sample script
#! /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 the remote server script 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
This method is very convenient.-t virtualizes a remote server terminal, which saves a lot of time when multiple servers are deployed at the same time!
SSH password-free login configuration http://www.linuxidc.com/Linux/2013-03/80488.htm under CentOS 6.0
Approach to improving the SSH login authentication speed for Ubuntu http://www.linuxidc.com/Linux/2014-09/106810.htm
Enable SSH service for Android phones to remotely access Ubuntu 14.04 http://www.linuxidc.com/Linux/2014-09/106809.htm
How to add a dual authentication http://www.linuxidc.com/Linux/2014-08/105998.htm for SSH in Linux
Configure the SFTP environment http://www.linuxidc.com/Linux/2014-08/105865.htm for non-SSH users in Linux
Http://www.linuxidc.com/Linux/2014-06/103627.htm for configuring and managing SSH services on Linux
SSH getting started basic learning tutorials http://www.linuxidc.com/Linux/2014-06/103008.htm
This article permanently updates the link address: Http://www.linuxidc.com/Linux/2015-01/111892.htm