![]() ![]() It can be configured using following steps: To overcome this, we can use public-private key authentication mechanism. In our case we’ll use it with bash as follows: $ ssh bash -c "' echo $msg '" Configure password-less SSH sessionīy default, SSH will ask for password authentication each time. To resolve this issue, we need to use -c option of shell. When we execute above command, we can observe that variable is not getting expanded. Let us see it with simple example: $ msg="Hello LinuxTechi" If we split commands into multiple lines, then variable expansion will not work. Make script executable and run it on remote server as follows: $ chmod +x system-info.shĪs some of you might have guessed, it will generate below output: Linux Let us create a simple shell script with following contents and name it as system-info.sh #!/bin/sh We just have to provide absolute path of local script to SSH command. Remote execution is not only limited to the commands we can even execute script over SSH. ![]() sudo command requires interactive terminal hence this option is necessary. Note that we have used ‘ -t‘ option with SSH, which allows pseudo-terminal allocation. Sometimes we need to execute command with elevated privileges, in that case we can use it with sudo. Thu Mar 1 15:47: Execute command with elevated privileges $ ssh "uname hostname date"Īs expected, these commands will generate below output: Linux We just need to separate commands with semicolon ( ). Using this technique, we can execute multiple commands using single SSH session. It’ll generate below output: Linux Execute multiple commands We have appended command to be executed (highlighted in red color). If you observe above command, it is similar to regular SSH command with minor difference. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |