-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.
Chinese translation: It is a virtual tty terminal that can provide a remote server. With this parameter, we can enter our own privilege escalation password on the virtual terminal of the remote server. Very safe
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
locally via ssh Script for remote server
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 still very convenient. -t virtualizes the terminal of a remote server, which really saves a lot of time when multiple servers are deployed at the same time!