when you do an "ssh second_machine" you are able to connect to second_machine on your home directory
But usually i am working in my_machine in directory with very long path, and i want to connect to second_machine and move to my working directory right away. So everytime i have to:
ssh second_machine
cd /very/long/path/to/directory/
Is there a way to make it automatic ?? ( ssh automatically go to the desired 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.
To list all files and directories using an SSH client, you would need to execute the appropriate command. The command name, in this case, is ls and it accepts various parameters. the output will be all visible files and folders without additional formatting or information.
Your SSH config file allows you to define specific settings for each SSH host that makes connecting to that host far easier. By defining many of these common, or uncommon, properties within the file, it eliminates the need to remember this parameter set each and every time a connection is needed.
This should work for you
ssh -t second_machine "cd /very/long/path/to/directory/; bash"
Assumes you're wanting to run bash, substitute for a different shell if required.
To make it permanent, use RemoteCommand
in your ~/.ssh/config
file, e.g.
Host myhost HostName IP User ubuntu IdentityFile ~/.ssh/id_rsa RemoteCommand cd /path/to/directory; $SHELL -il
Related:
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