[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: login into a particular directory using ssh



On Sun, Dec 05, 2004 at 05:33:14PM -0500, Kamaraju Kusumanchi wrote:
> On Sun, 05 Dec 2004 17:18:54 -0500, David Mandelberg
> <mandelbergd@eth0.is-a-geek.org> wrote:
> > ssh user@hostname "sh -c 'cd dirname; exec somecommand'"
> > 
> > somecommand is the command you want to run after cd'ing. E.g. if you
> > want to run bash in / as joe at shell.example.net:
> > 
> > ssh joe@shell.example.net "sh -c 'cd /; exec bash'"
> > 
> 
> I tried this. It is not working. The machine seems to be hanging. Is
> there any typo there?

It's not working here either. It's not hanging, but is waiting for
more input, probably due to wrong quotes. At least I'm logged in at
another console and can see no attempt at a second login.

In my case a simple command like:

ssh maurits@vanrees.org ls

works fine. So it seems a question of working out how the command
should be quoted. When I do it like this:

ssh maurits@vanrees.org sh -c "cd /; bash"

then it basically works. It doesn't give a prompt, but I can type
commands on the remote machine. It can look like this:

maurits@mauritsvanrees:~$ hostname
mauritsvanrees
maurits@mauritsvanrees:~$ ssh maurits@vanrees.org sh -c "cd /; bash"
hostname
vanrees.org

Wait, I notice that the `cd /' has no effect. In the original case it
actually works, but also without the prompt, so I didn't notice at
first. :)

ssh joe@shell.example.net "sh -c 'cd /; exec bash'"

and just start typing commands.

How to get a decent prompt is left as an exercise to the reader. :)

-- 
Maurits van Rees | http://maurits.vanrees.org/ [Dutch/Nederlands]
"Let your advance worrying become advance thinking and planning."
 - Winston Churchill



Reply to: