How to exit from SSH in LocalCommand?

Published on Author Code Father
How to exit from SSH in LocalCommand?

Solution 1:

ssh foo@bar.com  'cd foo/bar && rm *.foobar'

This will still print the output in the stdout but exit by default after executing the command.

Solution 2 :

Solution specific to your use-case : Based on the comment where you had mentioned, you will use ssh only for this ssh command,

You could edit the file called, /etc/profile

At the last line, just make all the commands, you want to execute, and then type exit

Ex :

ls / > /tmp/output
exit

This will run the command and exit the session

and you could just call it using, ssh user@host , nothing else.

PS : This will only run the command and exit, remember, if you wanted to ssh into the system for anything, this would not let you, unless you remove the exit in the last line.

Comments

comments