how to ssh to the remote path?

10

2

I have a folder in ~/apps/ and another one in the root /apps/

I want to ssh to them

ssh user@abc.com:~/apps/

and

ssh user@abc.com:/apps/ 

I got the following error:

Could not resolve hostname

What did I do wrong?

mko

Posted 2011-02-24T04:55:48.657

Reputation: 869

you found a solution? – dnl – 2011-02-24T13:35:52.603

@dnl I haven't found out yet, I want to use git to push my local repo to the remote site, but I need to ssh to a path – mko – 2011-02-24T15:05:22.673

than I suggest you should ask simple the question how to do this :) you might find your answer here: http://book.git-scm.com/3_distributed_workflows.html

– dnl – 2011-02-24T15:10:04.037

Answers

21

ssh user@server -t "cd /some/directory; bash --login"
  • -t keeps up the connection if there is user interaction)
  • the "command" is in quotes
  • bash --login is required to keep up the connection after the cd (see -t)

dnl

Posted 2011-02-24T04:55:48.657

Reputation: 326

Its worked 100% for me. ;) – user1635700 – 2018-03-08T06:43:29.050

see comments underneath questions for more information – dnl – 2011-02-24T15:43:26.743

4

I think you are mixing scp and ssh

For ssh you do not need to specify the destination path. You just log in as user@host.com and you land into the user's home folder.

Ozair Kafray

Posted 2011-02-24T04:55:48.657

Reputation: 1 030

3

SSH expects the following syntax:

ssh [other_options] [user@]hostname [command]

so when you typed:

ssh user@abc.com:~/apps/

SSH understood that you want to connect to a host named "abc.com:~/apps/" with a user "user". Since that host does not exist, you receive the error you quoted.

You will have to break your command into two like this:

ssh user@abc.com
(type the password, and wait for ssh to log you in)
cd ~/apps/

Yuriy Nemtsov

Posted 2011-02-24T04:55:48.657

Reputation: 215

2

Edit: You can always ssh as user@abc.com and then just navigate to the desired folder using cd folderName

Ozair Kafray explained it better

mixkat

Posted 2011-02-24T04:55:48.657

Reputation:

0

Below let me to login & go to a directory in one line, on ubuntu:

ssh user@abc.com -t "cd /path/to/your/directory/; `echo $SHELL --login`"

OR just

ssh user@abc.com -t "cd /path/to/your/directory/; bash --login"

Best of luck

Manohar Reddy Poreddy

Posted 2011-02-24T04:55:48.657

Reputation: 231