From the command line I'd like to open a new Terminal window that is already SSH'ing to a host.
From the command line, I can open a new Terminal window very easily:
open -a Terminal
or
open -a Terminal /path/name
(The second one starts the Terminal already "cd"'ed to /path/name.)
However I want the Terminal to open and immediately run "ssh foo" instead.
Best Answer
There is a way to do this with
Replace 'localhost' with the host name to which you wish to connect. You can include a username if the remote name is different from your local username, this would look like
This suggestion is a variation on the top answer at https://stackoverflow.com/questions/31524499/open-terminal-from-shell-and-execute-commands
Use
exec ssh
instead ofssh
if you want the window to close after logging out. If you use the 'exec ssh' option and your window stays open, then check your Terminal preferences--under "Profiles" > "Shell" > "When the shell exits:" is probably set to "Don't close the window"