1

I want to have something like this:

#!/bin/bash 
ssh 10.0.0.1
vncviewer

However, I want "vncviewer" command to be launched at the same time, and so that it does not interrupt with SSH asking me for password.

DisplayMyName
  • 223
  • 3
  • 9

1 Answers1

0

If your goal is to run vncviewer on the local machine, but only after you have entered your password for ssh, you can make a conditional link between the two commands

ssh 10.0.0.1 && vncviewer
Don Simon
  • 11
  • 2
  • I want vncviewer to launch on local machine. – DisplayMyName Oct 10 '18 at 19:31
  • 2
    In that case, your script probalby should look like this: vncviewer & ssh 10.0.0.1 – Don Simon Oct 10 '18 at 19:35
  • I tried that. It messes up with ssh asking me for a password. It somehow inputs a wrong one twice, and I am not able to do anything any more, just ctrl-c. – DisplayMyName Oct 10 '18 at 19:40
  • What do you mean “it messes up with ssh”...are you saying you can’t see the SSH prompt for passwords? Vncviewer is not piping input to ssh in any of the command lines you’ve given, so it wouldn’t be sending ipasswords. SSH on the other hand CAN tell if you don’t have a tty open, nor a public key available. – Don Simon Oct 10 '18 at 19:45
  • Yes, I login without keys, only with a password. And I can't enter them in this case. – DisplayMyName Oct 10 '18 at 19:46
  • OK, to make sure I understand, you want to start ssh, enter passwords, and then have vncviewer running, so sounds like your best choice would be to setup the execution of vncviewer to occur after a successful authentication to your remote server: ssh 10.0.0.1 && vncviewer Now, ssh will initiate, request your password while it still has control of the tty, and only IF your ssh connection is established, pass the screen on to vncviewer. – Don Simon Oct 10 '18 at 19:50
  • Yes, that would work for me. Thank you, will try tomorrow. – DisplayMyName Oct 10 '18 at 19:52
  • Using `&&` will not run `vncviewer` until `ssh` has exited, i.e. after the connection has opened *and closed*. See ["Execution of a command locally after ssh tunneling"](https://superuser.com/questions/1364162/execution-of-a-command-locally-after-ssh-tunneling) (thanks @KamilMaciorowski) for a better answer. – Gordon Davisson Oct 11 '18 at 00:14