How to configure SSH with a RemoteCommand only for interactive sessions (i.e. without command, or not sftp)
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
Currently I use Fish as my main shell on local and remote hosts.
I connect to remote hosts via ssh and sftp. I wanted to open or reuse a remote tmux whenever I connect, automatically, by default; so I added this to my ~/.ssh/config
:
Host example.com
RemoteCommand tmux a; or tmux
RequestTTY yes
The problem is that now I cannot connect through sftp
, nor can I run a direct command from my local CLI:
⤠ssh example.com ping localhost
Cannot execute command-line and remote command.
⤠sftp example.com
Cannot execute command-line and remote command.
Connection closed
So, my question is: How can I define a default command to be executed when opening a new interactive SSH session, but make it overridable?
ssh sftp ssh-config
add a comment |Â
up vote
1
down vote
favorite
Currently I use Fish as my main shell on local and remote hosts.
I connect to remote hosts via ssh and sftp. I wanted to open or reuse a remote tmux whenever I connect, automatically, by default; so I added this to my ~/.ssh/config
:
Host example.com
RemoteCommand tmux a; or tmux
RequestTTY yes
The problem is that now I cannot connect through sftp
, nor can I run a direct command from my local CLI:
⤠ssh example.com ping localhost
Cannot execute command-line and remote command.
⤠sftp example.com
Cannot execute command-line and remote command.
Connection closed
So, my question is: How can I define a default command to be executed when opening a new interactive SSH session, but make it overridable?
ssh sftp ssh-config
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
Currently I use Fish as my main shell on local and remote hosts.
I connect to remote hosts via ssh and sftp. I wanted to open or reuse a remote tmux whenever I connect, automatically, by default; so I added this to my ~/.ssh/config
:
Host example.com
RemoteCommand tmux a; or tmux
RequestTTY yes
The problem is that now I cannot connect through sftp
, nor can I run a direct command from my local CLI:
⤠ssh example.com ping localhost
Cannot execute command-line and remote command.
⤠sftp example.com
Cannot execute command-line and remote command.
Connection closed
So, my question is: How can I define a default command to be executed when opening a new interactive SSH session, but make it overridable?
ssh sftp ssh-config
Currently I use Fish as my main shell on local and remote hosts.
I connect to remote hosts via ssh and sftp. I wanted to open or reuse a remote tmux whenever I connect, automatically, by default; so I added this to my ~/.ssh/config
:
Host example.com
RemoteCommand tmux a; or tmux
RequestTTY yes
The problem is that now I cannot connect through sftp
, nor can I run a direct command from my local CLI:
⤠ssh example.com ping localhost
Cannot execute command-line and remote command.
⤠sftp example.com
Cannot execute command-line and remote command.
Connection closed
So, my question is: How can I define a default command to be executed when opening a new interactive SSH session, but make it overridable?
ssh sftp ssh-config
asked Jun 22 at 8:39
Yajo
1484
1484
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
Option 1 )
You can the option Match ( see man ssh_config )
Match Host example.com exec "test $_ = /usr/bin/ssh"
RemoteCommand tmux a; or tmux
RequestTTY yes
This will only differentiate difference between ssh & sftp
Option 2
You create some placeholder config for your diffe command , example :
Host tmux.example.com
HostName example.com
HostKeyAlias example.com
RemoteCommand tmux a; or tmux
RequestTTY yes
And after you can still use example.com for you sftp / ping usage .
1st option didn't work. It seems Fish doesn't export$_
. However, I can manually export a variable withset -x auto_tmux 1
and change the match test to"[ 1 -eq $auto_tmux ]"
â Yajo
Jun 25 at 9:04
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Option 1 )
You can the option Match ( see man ssh_config )
Match Host example.com exec "test $_ = /usr/bin/ssh"
RemoteCommand tmux a; or tmux
RequestTTY yes
This will only differentiate difference between ssh & sftp
Option 2
You create some placeholder config for your diffe command , example :
Host tmux.example.com
HostName example.com
HostKeyAlias example.com
RemoteCommand tmux a; or tmux
RequestTTY yes
And after you can still use example.com for you sftp / ping usage .
1st option didn't work. It seems Fish doesn't export$_
. However, I can manually export a variable withset -x auto_tmux 1
and change the match test to"[ 1 -eq $auto_tmux ]"
â Yajo
Jun 25 at 9:04
add a comment |Â
up vote
1
down vote
accepted
Option 1 )
You can the option Match ( see man ssh_config )
Match Host example.com exec "test $_ = /usr/bin/ssh"
RemoteCommand tmux a; or tmux
RequestTTY yes
This will only differentiate difference between ssh & sftp
Option 2
You create some placeholder config for your diffe command , example :
Host tmux.example.com
HostName example.com
HostKeyAlias example.com
RemoteCommand tmux a; or tmux
RequestTTY yes
And after you can still use example.com for you sftp / ping usage .
1st option didn't work. It seems Fish doesn't export$_
. However, I can manually export a variable withset -x auto_tmux 1
and change the match test to"[ 1 -eq $auto_tmux ]"
â Yajo
Jun 25 at 9:04
add a comment |Â
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Option 1 )
You can the option Match ( see man ssh_config )
Match Host example.com exec "test $_ = /usr/bin/ssh"
RemoteCommand tmux a; or tmux
RequestTTY yes
This will only differentiate difference between ssh & sftp
Option 2
You create some placeholder config for your diffe command , example :
Host tmux.example.com
HostName example.com
HostKeyAlias example.com
RemoteCommand tmux a; or tmux
RequestTTY yes
And after you can still use example.com for you sftp / ping usage .
Option 1 )
You can the option Match ( see man ssh_config )
Match Host example.com exec "test $_ = /usr/bin/ssh"
RemoteCommand tmux a; or tmux
RequestTTY yes
This will only differentiate difference between ssh & sftp
Option 2
You create some placeholder config for your diffe command , example :
Host tmux.example.com
HostName example.com
HostKeyAlias example.com
RemoteCommand tmux a; or tmux
RequestTTY yes
And after you can still use example.com for you sftp / ping usage .
answered Jun 24 at 4:14
EchoMike444
3942
3942
1st option didn't work. It seems Fish doesn't export$_
. However, I can manually export a variable withset -x auto_tmux 1
and change the match test to"[ 1 -eq $auto_tmux ]"
â Yajo
Jun 25 at 9:04
add a comment |Â
1st option didn't work. It seems Fish doesn't export$_
. However, I can manually export a variable withset -x auto_tmux 1
and change the match test to"[ 1 -eq $auto_tmux ]"
â Yajo
Jun 25 at 9:04
1st option didn't work. It seems Fish doesn't export
$_
. However, I can manually export a variable with set -x auto_tmux 1
and change the match test to "[ 1 -eq $auto_tmux ]"
â Yajo
Jun 25 at 9:04
1st option didn't work. It seems Fish doesn't export
$_
. However, I can manually export a variable with set -x auto_tmux 1
and change the match test to "[ 1 -eq $auto_tmux ]"
â Yajo
Jun 25 at 9:04
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f451253%2fhow-to-configure-ssh-with-a-remotecommand-only-for-interactive-sessions-i-e-wi%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password