Overview
Using the ‘ssh’ command with the ‘-t’ parameter, we can run commands on a remote server.
Syntax:
ssh user@server – t “Command to be executed at server”
Examples:
#Running chef-solo on remote server
CHEF_TARGET = "ssh -v ec2-user@ec2-52-24-147-93.us-west-2.compute.amazonaws.com"
CHEF_ROLE="my-app"
ssh ec2-user@ec2-55-124-347-93.us-west-2.compute.amazonaws.com -t "sudo chef-solo --node-name $CHEF_TARGET -o role[$CHEF_ROLE]"
#Performing list command on remote server
ssh ec2-user@10.24.256.11 - t "ls -la"
#Creating a directory at remote server
ssh -i pemfile.pem ec2-user@10.24.256.11 - t "sudo mkdir -p /root/home/test"
Note: – For authentication on the server, you can use the following two ways.
- Public-Private keys based authentication
- Password-based authentication