Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSH config file paragraph to open a specific directory on remote server [closed]

Tags:

Is there a way to specifically ssh into a particular directory in remote location, specifically using the local ssh config file (not terminal)? Something like Dir option in the paragraph below, for example,

    Host remote_dir        Hostname remote_server        User username        Dir path/to/remote_dir/ 

So, if I, ssh using the Host value from above paragraph,

ssh remote_dir 

Then, I would like to be logged in and the terminal to be ready for me at path/to/remote_dir/ of the remote server,

username@remote_server: path/to/remote_dir/ > pwd /home/username/path/to/remote_dir/ 
like image 775
Jay Avatar asked Jan 17 '13 20:01

Jay


People also ask

Can you ssh to a specific directory?

Meaning - we can automatically change to a particular directory when log in to a remote system via SSH. Not just SSH into a specific directory, it is even possible run any command immediately right after connecting to the remote server over SSH.

Where do I put ssh config?

OpenSSH client-side configuration file is named config , and it is stored in the . ssh directory under the user's home directory.

What is config file in ssh folder?

SSH client configuration files allow us to connect to servers with pre-configured commands. This saves typing each SSH command parameter when logging into a remote machine and executing commands on a remote device. This article will examine secure shell (SSH) client configuration (config) files and their functions.


1 Answers

In this post on ServerFault, they say you can't do it all through the ssh config file. But you can do it with the ssh config and your .bash_profile or whatever the terminal nerds call it. in the ssh config file add

Host dev   Hostname server.com   User joe 

then in your .bash_profile add an alias

alias domain1="ssh dev -t 'cd domains/domain1; bash'" 

Here the dev refers to what you set up in the config file.

In the Terminal, just type domain1, you will be asked to put in your password and will go straight to the directory. Make a new alias for all your domains and it will make logging in to each one super easy.

like image 50
Jay Avatar answered Sep 24 '22 02:09

Jay