I was trying the following combination in order to get the pid of the ssh session (running in the background displays the pid) and than fg to get back to the ssh session and introduce the password: ssh targetHost &; fgI get the following error: -bash: syntax error near unexpected token `;'Why does the ; not work to as expected in this case? My aim is to start a ssh session and know its pid and I need to do this in as few lines as possible. I need to start several ssh sessions, put them in the background and at the end kill them - that's why I need the pids. 
ssh targetHost &; fg - does not work, but why?
background process;pid
You are mixing up two different cases:foo ; bar will run foo, wait for it to finish and then run barfoo & bar will start foo, put it in background and start bar directly afterwards.You have to decide, either use the one or the other. You cannot do both. ;)To solve you problem, you can simply run all jobs in background and then use job to list the pids:michas@lenny:~$ sleep 10 &[1] 18007michas@lenny:~$ sleep 10 &[2] 18011michas@lenny:~$ sleep 10 &[3] 18015michas@lenny:~$ sleep 10 &[4] 18019michas@lenny:~$ sleep 10 &[5] 18026michas@lenny:~$ jobs -p1800718011180151801918026michas@lenny:~$ You also do not necessarily need the pids to send kill signals. For example kill %1 will kill the first background process.