I know I can execute a command on a remote machine using "ssh ip_addr "command"", and this will return after 'command' exits. How can I execute a command in the background on the remote machine so that I don't need to wait for the 'command' to exits? I tried ssh ipaddr "command &amp;" but it didn't seems to work. An alternative is ssh ipaddr "command" &amp; which put the ssh command in the background but it doesn't look clean. Suggestions?
36928
This is a follow-on question to the  question.  If I want to execute a command on the remote machine that runs in the background on that machine, how do I get the ssh command to return?  When I try to just include the ampersand (&amp;) at the end of the command it just hangs.  The exact form of the command looks like this: ssh user@target &quot;cd /some/directory; program-to-execute &amp;&quot;  Any ideas?  One thing to note is that logins to the target machine always produce a text banner and I have SSH keys set up so no password is required.
32475
If I'm logged into a remote Linux machine, I know I can suspend a process (cntr-z) and move it to the background (bg 1) but if I disconnect from the machine, the process stops.  Is there a way I can leave it in the background and have it there when I log back in? This is a very long running process.  On Ubuntu, logged in via SSH.
49345
I was wondering if it's possible to run an Ubuntu virtual machine using VirtualBox in background, I mean, without any window open.  The idea is to connect via SSH to the Linux host, that would be running in background.  Has anyone ever done something like this? Is it possible?
79917
Im trying to measure bandwidth, packet loss, latency and jitter between two computers on a wireless 802.11s mesh connection.   Im trying to make a (my first) bash script that can do the following:   SSH to another computer and start logging data from services (ptpd, tcpdump, iperf). Start the same processes on my own computer and start logging data. Once the iperf transmission on my own computer is finished, it should SSH into the remote computer and kill the the services.   The idea is for this these three steps run in a for-loop, that increases the package size transmitted by iperf for each iteration and logs the resulting data.  I know how to start a process on the remote pc by ssh host@adress process.  I am however clueless on how to start multiple processes through SSH and logout, since the processes are terminated once I logout. I have looked at the screen and nohup commands, but don't know how to use them in a script.  Thanks in advance!  EDIT:  Thanks for all the help so far.  I got nohup to work now, it was pretty simple as people pointed out.  So now I got: ssh host@adress nohup ./script.sh &gt; /dev/null 2&gt;&amp;1 &amp; in the script on my main pc. This starts a script on the remote pc just fine, and then logout of SSH. The next problem is how to execute the script on the remote pc as sudo, since this is needed by tcpdump.  Trying ssh host@adress **sudo** nohup ./script.sh &gt; /dev/null 2&gt;&amp;1 &amp; doesnt work.  Any ideas?  EDIT 2:  If anybody is stuck with the same problem, I found a guide how to solve this:
6988
My wife is sitting at her home desktop, alpha, which is running a recent version of Ubuntu.  I am on a bus, using ConnectBot on my G1 phone, and can SSH into alpha from wherever I am.  For complicated reasons, I cannot use IM, email, or the telephone in order to contact her.  (E.g. I don't want to wake the baby, my IM client is broken, my email server is down.)  My only option is to ssh into alpha remotely and try to somehow make something appear on the screen.  She's using KDE; how can I make something pop up to get her attention and let her know I'm trying to communicate with her?  I thought it was possible to remotely trigger something (like xmessage) to appear on her screen even though my SSH session doesn't have an X display.  EDIT: To clarify, my phone is not running any flavor of X, so X-over-ssh is not possible.  Would the following work?  $ export DISPLAY=:0 $ xmessage "test"
97141
I have a script file ./run_app.sh which contains of the following:  ssh -L 8888:localhost:8888 ubuntu@address ./run_website.sh   # it should be executed locally   but it tries to run the second line on the remote machine. Actually, I want to run it on my pc. Any idea?
18512
I have a script that works well when I ssh to the server to execute it myself, but has problems when , a continuous integration server, runs it.  I am automating tests on an embedded linux system (the target). The target is connected to Server A (RHEL 5) via serial and operated over minicom. Server B (FC 12) builds the tests that actually run on the target, and can ssh to Server A. Server C (RH) hosts Hudson, with Server B as a slave.   I've written a runscript (http://linux.die.net/man/1/runscript) script to do everything needed on the actual target; it boots the image, mounts a directory from Server B and executes the tests. A bash script on Server B invokes minicom with the runscript script along with some companion actions. I have a bash script on Server B which uses   ssh -t -t ServerA bashScript.sh   to get those tests run on the target. I am on Server C, I can get those tests run by ssh'ing to Server B and executing the script that ssh's to Server A which executes minicom with runscript. Whew.  To review:  Server A: Hudson uses its slave mechanism to ssh to Server B.  Server B: kickOffTests.sh has the line ssh -t -t ServerA runTests.sh  Server A: runTests.sh calls a perl script which invokes minicom -S my.script ttyE1  Target, after booting: Mounts a directory from Server B, where the tests are, and enters that directory. It invokes yet another bash script, which runs the tests, which are compiled C executables.  Now, when I execute any of these scripts myself, they do what they should. However, when Hudson tries to do the same thing, over in the minicom session it complains about a line in the "yet another bash script" that invokes the C executable, ./executable, with ./executable: cannot execute binary file  I still have a lot to learn about linux, but I surmise this problem is a result of Hudson not connecting with a console. I don't know exactly what Hudson does to control its slave. I tried using the line export TERM=console in the configuration just before running kickOffTests.sh, but the problem remains.  Can anyone explain to me what is happening and how I can fix it? I cannot remove any of the servers from this equation. It may be possible to take minicom out of the equation but that would add an unknown amount of time to this project, so I'd much prefer a solution that uses what I already have.
39469
Is there a way to run a script/command every time a user connects using ssh? Can it be configured globally (i.e run the script when any user login)?  I came across this question on Identica, but there is no answer yet and would like to know it anyway.
116137
Is there a way to back out of all SSH connections and close  in "one shot"?  I work in Windows 7 and use PuTTY to SSH to various Linux hosts.  An example of the way I find myself working:  SSH to host1 with PuTTY... banjer@host1:~&gt; #...doin some work...ooh! need to go check something on host8... banjer@host1:~&gt; ssh host8 banjer@host8:~&gt; #...doin some work...OK time for lunch. lets close putty... banjer@host8:~&gt; exit banjer@host1:~&gt; exit Putty closes.   Per above, any way to get from host8 to closing PuTTY in one shot?  Sometimes I find myself up to 5 or 10 hosts deep.  I realize I can click the X to close the PuTTY window, but I like to make sure my SSH connections get closed properly by using the exit command.  I also realize I'm asking for tips on how to increase laziness.  I'll just write it off as "how can I be more efficient".
2844
I'm working on a Linux machine through SSH (Putty). I need to leave a process running during the night, so I thought I could do that by starting the process in background (with an ampersand at the end of the command) and redirecting stdout to a file.  To my surprise, that doesn't work. As soon as I close the Putty window, the process is stopped.  How can I prevent that from happening??
108210
On my remote machine, an xterm/shell has been created (by another process). I have full access to that shell through VNC. But really I would like to be using a text mode shell on my local machine.  How can I control the existing remote shell from a local one?  I can't create a new shell, that's the point.  But I have non-privileged access to the existing remote shell.
29921
Here's my situation: I'm setting up a test harness that will, from a central client, launch a number of virtual machine instances and then execute commands on them via ssh.  The virtual machines will have previously unused hostnames and IP addresses, so they won't be in the ~/.ssh/known_hosts file on the central client.  The problem I'm  having is that the first ssh command run against a new virtual instance always comes up with an interactive prompt:  The authenticity of host '[hostname] ([IP address])' can't be established. RSA key fingerprint is [key fingerprint]. Are you sure you want to continue connecting (yes/no)?   Is there a way that I can bypass this and get the new host to be already known to the client machine, maybe by using a public key that's already baked into the virtual machine image ?  I'd really like to avoid having to use Expect or whatever to answer the interactive prompt if I can.
63786
I'm using a GNU/Linux system remotely, via SSH.  I mistakenly added something into my $HOME/.bash_profile scriot which causes an error. (To be specific: I added an exec foo command instead of . foo, applied to another bash script without execution permissions, which results in an error.)   Now I can't seem to SSH, SCP or SFTP into my machine: bash, my login shell, tries to run the exec foo command, gets the error and throws me out! I don't have any other account I can access remotely.  Is there something I can do to restore access to the system?  Additional details:   Most ports other than for SSH are unavailable since the machine is behind a firewall. It's a Devuan 3 ASCII (~= Debian 10 Beowulf) system.
56386
Each time putty is closing the session after some time if it is idle.  There is no time parameter on putty, so how can I keep my putty ssh session always Alive?
64474
This is a question that has been addressed several times, not only here, but also in other sites of the stack exchange network (e.g. ). However, I cannot make any of the solutions work for me.  I'm running a command through ssh. Whenever I exit ssh, I want the command to die as well. This command is a daemon called ktserver that runs indefinitely until you press Ctrl-C.  I run it as follows: ssh -t compute-0-1 ktserver and, indeed, when I press Ctrl-C, the process ends gracefully and the ssh session ends.  However, if instead of pressing Ctrl-C, I kill the ssh process using the kill command (for example, sending SIGINT or SIGHUP), the ktserver process stays alive.  How can I make the ktserver always die independent on how ssh is killed?  EDIT: If, instead of ktserver I run something completely different, such as gedit, everything works like a charm (i.e. gedit dies when the connection dies). Therefore, there might be something wrong with the process itself. For example, I thought that it might be ignoring SIGHUP or SIGINT. However, when I run kill -1 ktserver or kill -2 ktserver, the process dies as expected.  EDIT2: As Mark Plotnick points out, the issue is related to the fact that there is no communication circulating on the ssh channel. I've confirmed by running ssh -t &lt;host&gt; read and killing the ssh process afterwards. readwas still alive and kicking.
50241
I'm trying to spawn an SSH from my bash profile script that runs in the background for connection sharing (via its control socket). The problem I'm running into is a reliable way to ensure the SSH doesn't stay running once the TTY is closed (or more directly; once the parent bash shell has exited).    I know the shell can run commands (to terminate SSH) when it exits gracefully, but I'm trying to handle all possible scenarios where the shell doesn't get a chance to shut things down.  Is there a clever way I can do this?  The best idea I've had is   ssh -o PermitLocalCommand=yes -o LocalCommand='cat &gt;/dev/null; kill $PPID' $HOST &amp;   But this won't work because I need the command to only background once it has successfully started. Alternatively, I can't use -fN instead of the shell's &amp; because the SSH -f only backgrounds after the LocalCommand has completed.  Also I'm trying to avoid running any command on the remote host. Otherwise I could probably do something like ssh -fN $HOST 'cat &gt;/dev/null'
4738
I sometimes have long running processes that I want to kick off before going home, so I create a SSH session to the server to start the process, but then I want to close my laptop and go home and later, after dinner, I want to check on the process that I started before leaving work. How can I do that with SSH? My understanding is that if you break your SSH connection you will also break your login session on the server, therefore killing the long running process.