December 29, 20223 yr Hello, I am trying to run an SSH command that will login and then cd to a certain directory and keep the terminal window open. So far, I have tried several variations of: ssh -t root@<ip> "cd /foo/dir; bash --login" Unfortunately, it always will go back to the home ~ directory. Running ssh -t root@<ip> "cd /foo/dir; pwd" successfully prints the target directory so I know that the first part works, but the bash part must be where there's an issue. Does anyone have any insight into how I can get this working?
January 1, 20233 yr Community Expert You could do this: ssh -t root@<ip> "cd /foo/dir && exec $SHELL"
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.