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/
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.
OpenSSH client-side configuration file is named config , and it is stored in the . ssh directory under the user's home directory.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With