15

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

I want to ssh to them

ssh [email protected]:~/apps/

and

ssh [email protected]:/apps/ 

I got the following error:

Could not resolve hostname

What did I do wrong?

3
  • you found a solution?
    – Daniel K
    Feb 24, 2011 at 13:35
  • @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
    Feb 24, 2011 at 15:05
  • than I suggest you should ask simple the question how to do this :) you might find your answer here: book.git-scm.com/3_distributed_workflows.html
    – Daniel K
    Feb 24, 2011 at 15:10

5 Answers 5

28
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)
2
  • see comments underneath questions for more information
    – Daniel K
    Feb 24, 2011 at 15:43
  • Its worked 100% for me. ;) Mar 8, 2018 at 6:43
5

SSH expects the following syntax:

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

so when you typed:

ssh [email protected]:~/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 [email protected]
(type the password, and wait for ssh to log you in)
cd ~/apps/
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 [email protected] and you land into the user's home folder.

2

Edit: You can always ssh as [email protected] and then just navigate to the desired folder using cd folderName

Ozair Kafray explained it better

0

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

ssh [email protected] -t "cd /path/to/your/directory/; `echo $SHELL --login`"

OR just

ssh [email protected] -t "cd /path/to/your/directory/; bash --login"

Best of luck

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .