How to SSH into a specific directory? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Community Moderator Election Results Why I closed the “Why is Kali so hard” questionProblem with colons in ssh commandDifference between Login Shell and Non-Login Shell?Remote command in ssh config filecan't get gnome-session working over SSHCan I recursively print all current remote shells?SSH tunnel through middleman server - how to connect in one step (using key pair)?How to securely allow scp, but not sshDifferent ssh login directory from user homeSSH to 2 local machines via Unix serverSpecific user's SSH-RSA with root access (via AWS EC2)Automatically entering ssh password from Busybox terminalCan't SSH into localhostSSH public key exchange
How to tell that you are a giant?
Overriding an object in memory with placement new
Why light coming from distant stars is not discreet?
Using et al. for a last / senior author rather than for a first author
Identify plant with long narrow paired leaves and reddish stems
What's the purpose of writing one's academic biography in the third person?
What LEGO pieces have "real-world" functionality?
How can I make names more distinctive without making them longer?
Should I use a zero-interest credit card for a large one-time purchase?
Error "illegal generic type for instanceof" when using local classes
List *all* the tuples!
What does "fit" mean in this sentence?
Is it ethical to give a final exam after the professor has quit before teaching the remaining chapters of the course?
How do I keep my slimes from escaping their pens?
What is the role of the transistor and diode in a soft start circuit?
How does the particle を relate to the verb 行く in the structure「A を + B に行く」?
How to react to hostile behavior from a senior developer?
Check which numbers satisfy the condition [A*B*C = A! + B! + C!]
Why didn't this character "real die" when they blew their stack out in Altered Carbon?
Why aren't air breathing engines used as small first stages
What exactly is a "Meth" in Altered Carbon?
What would be the ideal power source for a cybernetic eye?
How to run gsettings for another user Ubuntu 18.04.2 LTS
How to bypass password on Windows XP account?
How to SSH into a specific directory?
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
2019 Community Moderator Election Results
Why I closed the “Why is Kali so hard” questionProblem with colons in ssh commandDifference between Login Shell and Non-Login Shell?Remote command in ssh config filecan't get gnome-session working over SSHCan I recursively print all current remote shells?SSH tunnel through middleman server - how to connect in one step (using key pair)?How to securely allow scp, but not sshDifferent ssh login directory from user homeSSH to 2 local machines via Unix serverSpecific user's SSH-RSA with root access (via AWS EC2)Automatically entering ssh password from Busybox terminalCan't SSH into localhostSSH public key exchange
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I frequently login to a server, then cd into a specific directory. Is it possible to simplify these two commands into one?
ssh bob@foo
cd /home/guest
I'd like to avoid changing anything on 'foo' if possible, as I'll have to clear it with the server administrator. I use bash, but I am open to answers in other shells.
bash ssh
add a comment |
I frequently login to a server, then cd into a specific directory. Is it possible to simplify these two commands into one?
ssh bob@foo
cd /home/guest
I'd like to avoid changing anything on 'foo' if possible, as I'll have to clear it with the server administrator. I use bash, but I am open to answers in other shells.
bash ssh
add a comment |
I frequently login to a server, then cd into a specific directory. Is it possible to simplify these two commands into one?
ssh bob@foo
cd /home/guest
I'd like to avoid changing anything on 'foo' if possible, as I'll have to clear it with the server administrator. I use bash, but I am open to answers in other shells.
bash ssh
I frequently login to a server, then cd into a specific directory. Is it possible to simplify these two commands into one?
ssh bob@foo
cd /home/guest
I'd like to avoid changing anything on 'foo' if possible, as I'll have to clear it with the server administrator. I use bash, but I am open to answers in other shells.
bash ssh
bash ssh
edited Aug 16 '13 at 6:19
spuder
asked Aug 15 '13 at 23:04
spuderspuder
6,8282671106
6,8282671106
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
Just put as the last line of your ~bob/.bash_profile file on foo:
cd /home/guest >& /dev/null
Now each time you log in (whether by SSH or otherwise), the cd command will run. No mucking around with ssh is necessary.
I know you wrote that you'd "like to avoid changing anything on 'foo' if possible," but if the bob@foo account is yours, changing your own .bash_profile should be acceptable, no?
2
Why yes, I think this will work great. I won't need to get permission from IT to make that change. Could you elaborate on why you need >& /dev/null ?
– spuder
Aug 16 '13 at 1:41
5
I think that should be&> /dev/null
. It prevents any error message that may be shown just in case cd fails to change directory to /home/directory. If you want to see those messages you could just exclude that.
– konsolebox
Aug 16 '13 at 4:54
3
>&
and&>
are the same in Bash. The latter style is preferred though.
– user26112
Aug 16 '13 at 11:16
Additionally, the redirection to /dev/null prevents the name of the directory from being echoed onscreen, which "cd" may do.
– DanB
Sep 11 '13 at 1:40
add a comment |
This works with OpenSSH:
ssh -t bob@foo 'cd /home/guest && exec bash -l'
The last argument runs in your login shell. The -t
flag passed to ssh
forces ssh
to allocate a pseudo-terminal, which is necessary for an interactive shell. The -l
flag passed to bash
starts bash as a login shell.
3
I wonder, would adding -l option to bash be helpful as well?... && exec bash -l
– konsolebox
Aug 16 '13 at 4:55
1
@konsolebox: That's a good idea. I have added that to my answer.
– user26112
Aug 16 '13 at 11:14
add a comment |
You can also do it this way, similar to @EvanTeitelman's solution:
$ ssh -t bob@foo "cd /tmp ; bash"
Or if you don't know the shell on the other end:
$ ssh -t bob@foo "cd /tmp && exec $SHELL"
Or like this:
$ ssh -t bob@foo 'cd /tmp && exec $SHELL'
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f86941%2fhow-to-ssh-into-a-specific-directory%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Just put as the last line of your ~bob/.bash_profile file on foo:
cd /home/guest >& /dev/null
Now each time you log in (whether by SSH or otherwise), the cd command will run. No mucking around with ssh is necessary.
I know you wrote that you'd "like to avoid changing anything on 'foo' if possible," but if the bob@foo account is yours, changing your own .bash_profile should be acceptable, no?
2
Why yes, I think this will work great. I won't need to get permission from IT to make that change. Could you elaborate on why you need >& /dev/null ?
– spuder
Aug 16 '13 at 1:41
5
I think that should be&> /dev/null
. It prevents any error message that may be shown just in case cd fails to change directory to /home/directory. If you want to see those messages you could just exclude that.
– konsolebox
Aug 16 '13 at 4:54
3
>&
and&>
are the same in Bash. The latter style is preferred though.
– user26112
Aug 16 '13 at 11:16
Additionally, the redirection to /dev/null prevents the name of the directory from being echoed onscreen, which "cd" may do.
– DanB
Sep 11 '13 at 1:40
add a comment |
Just put as the last line of your ~bob/.bash_profile file on foo:
cd /home/guest >& /dev/null
Now each time you log in (whether by SSH or otherwise), the cd command will run. No mucking around with ssh is necessary.
I know you wrote that you'd "like to avoid changing anything on 'foo' if possible," but if the bob@foo account is yours, changing your own .bash_profile should be acceptable, no?
2
Why yes, I think this will work great. I won't need to get permission from IT to make that change. Could you elaborate on why you need >& /dev/null ?
– spuder
Aug 16 '13 at 1:41
5
I think that should be&> /dev/null
. It prevents any error message that may be shown just in case cd fails to change directory to /home/directory. If you want to see those messages you could just exclude that.
– konsolebox
Aug 16 '13 at 4:54
3
>&
and&>
are the same in Bash. The latter style is preferred though.
– user26112
Aug 16 '13 at 11:16
Additionally, the redirection to /dev/null prevents the name of the directory from being echoed onscreen, which "cd" may do.
– DanB
Sep 11 '13 at 1:40
add a comment |
Just put as the last line of your ~bob/.bash_profile file on foo:
cd /home/guest >& /dev/null
Now each time you log in (whether by SSH or otherwise), the cd command will run. No mucking around with ssh is necessary.
I know you wrote that you'd "like to avoid changing anything on 'foo' if possible," but if the bob@foo account is yours, changing your own .bash_profile should be acceptable, no?
Just put as the last line of your ~bob/.bash_profile file on foo:
cd /home/guest >& /dev/null
Now each time you log in (whether by SSH or otherwise), the cd command will run. No mucking around with ssh is necessary.
I know you wrote that you'd "like to avoid changing anything on 'foo' if possible," but if the bob@foo account is yours, changing your own .bash_profile should be acceptable, no?
answered Aug 16 '13 at 1:36
DanBDanB
29614
29614
2
Why yes, I think this will work great. I won't need to get permission from IT to make that change. Could you elaborate on why you need >& /dev/null ?
– spuder
Aug 16 '13 at 1:41
5
I think that should be&> /dev/null
. It prevents any error message that may be shown just in case cd fails to change directory to /home/directory. If you want to see those messages you could just exclude that.
– konsolebox
Aug 16 '13 at 4:54
3
>&
and&>
are the same in Bash. The latter style is preferred though.
– user26112
Aug 16 '13 at 11:16
Additionally, the redirection to /dev/null prevents the name of the directory from being echoed onscreen, which "cd" may do.
– DanB
Sep 11 '13 at 1:40
add a comment |
2
Why yes, I think this will work great. I won't need to get permission from IT to make that change. Could you elaborate on why you need >& /dev/null ?
– spuder
Aug 16 '13 at 1:41
5
I think that should be&> /dev/null
. It prevents any error message that may be shown just in case cd fails to change directory to /home/directory. If you want to see those messages you could just exclude that.
– konsolebox
Aug 16 '13 at 4:54
3
>&
and&>
are the same in Bash. The latter style is preferred though.
– user26112
Aug 16 '13 at 11:16
Additionally, the redirection to /dev/null prevents the name of the directory from being echoed onscreen, which "cd" may do.
– DanB
Sep 11 '13 at 1:40
2
2
Why yes, I think this will work great. I won't need to get permission from IT to make that change. Could you elaborate on why you need >& /dev/null ?
– spuder
Aug 16 '13 at 1:41
Why yes, I think this will work great. I won't need to get permission from IT to make that change. Could you elaborate on why you need >& /dev/null ?
– spuder
Aug 16 '13 at 1:41
5
5
I think that should be
&> /dev/null
. It prevents any error message that may be shown just in case cd fails to change directory to /home/directory. If you want to see those messages you could just exclude that.– konsolebox
Aug 16 '13 at 4:54
I think that should be
&> /dev/null
. It prevents any error message that may be shown just in case cd fails to change directory to /home/directory. If you want to see those messages you could just exclude that.– konsolebox
Aug 16 '13 at 4:54
3
3
>&
and &>
are the same in Bash. The latter style is preferred though.– user26112
Aug 16 '13 at 11:16
>&
and &>
are the same in Bash. The latter style is preferred though.– user26112
Aug 16 '13 at 11:16
Additionally, the redirection to /dev/null prevents the name of the directory from being echoed onscreen, which "cd" may do.
– DanB
Sep 11 '13 at 1:40
Additionally, the redirection to /dev/null prevents the name of the directory from being echoed onscreen, which "cd" may do.
– DanB
Sep 11 '13 at 1:40
add a comment |
This works with OpenSSH:
ssh -t bob@foo 'cd /home/guest && exec bash -l'
The last argument runs in your login shell. The -t
flag passed to ssh
forces ssh
to allocate a pseudo-terminal, which is necessary for an interactive shell. The -l
flag passed to bash
starts bash as a login shell.
3
I wonder, would adding -l option to bash be helpful as well?... && exec bash -l
– konsolebox
Aug 16 '13 at 4:55
1
@konsolebox: That's a good idea. I have added that to my answer.
– user26112
Aug 16 '13 at 11:14
add a comment |
This works with OpenSSH:
ssh -t bob@foo 'cd /home/guest && exec bash -l'
The last argument runs in your login shell. The -t
flag passed to ssh
forces ssh
to allocate a pseudo-terminal, which is necessary for an interactive shell. The -l
flag passed to bash
starts bash as a login shell.
3
I wonder, would adding -l option to bash be helpful as well?... && exec bash -l
– konsolebox
Aug 16 '13 at 4:55
1
@konsolebox: That's a good idea. I have added that to my answer.
– user26112
Aug 16 '13 at 11:14
add a comment |
This works with OpenSSH:
ssh -t bob@foo 'cd /home/guest && exec bash -l'
The last argument runs in your login shell. The -t
flag passed to ssh
forces ssh
to allocate a pseudo-terminal, which is necessary for an interactive shell. The -l
flag passed to bash
starts bash as a login shell.
This works with OpenSSH:
ssh -t bob@foo 'cd /home/guest && exec bash -l'
The last argument runs in your login shell. The -t
flag passed to ssh
forces ssh
to allocate a pseudo-terminal, which is necessary for an interactive shell. The -l
flag passed to bash
starts bash as a login shell.
edited Apr 13 '17 at 12:36
Community♦
1
1
answered Aug 15 '13 at 23:17
user26112
3
I wonder, would adding -l option to bash be helpful as well?... && exec bash -l
– konsolebox
Aug 16 '13 at 4:55
1
@konsolebox: That's a good idea. I have added that to my answer.
– user26112
Aug 16 '13 at 11:14
add a comment |
3
I wonder, would adding -l option to bash be helpful as well?... && exec bash -l
– konsolebox
Aug 16 '13 at 4:55
1
@konsolebox: That's a good idea. I have added that to my answer.
– user26112
Aug 16 '13 at 11:14
3
3
I wonder, would adding -l option to bash be helpful as well?
... && exec bash -l
– konsolebox
Aug 16 '13 at 4:55
I wonder, would adding -l option to bash be helpful as well?
... && exec bash -l
– konsolebox
Aug 16 '13 at 4:55
1
1
@konsolebox: That's a good idea. I have added that to my answer.
– user26112
Aug 16 '13 at 11:14
@konsolebox: That's a good idea. I have added that to my answer.
– user26112
Aug 16 '13 at 11:14
add a comment |
You can also do it this way, similar to @EvanTeitelman's solution:
$ ssh -t bob@foo "cd /tmp ; bash"
Or if you don't know the shell on the other end:
$ ssh -t bob@foo "cd /tmp && exec $SHELL"
Or like this:
$ ssh -t bob@foo 'cd /tmp && exec $SHELL'
add a comment |
You can also do it this way, similar to @EvanTeitelman's solution:
$ ssh -t bob@foo "cd /tmp ; bash"
Or if you don't know the shell on the other end:
$ ssh -t bob@foo "cd /tmp && exec $SHELL"
Or like this:
$ ssh -t bob@foo 'cd /tmp && exec $SHELL'
add a comment |
You can also do it this way, similar to @EvanTeitelman's solution:
$ ssh -t bob@foo "cd /tmp ; bash"
Or if you don't know the shell on the other end:
$ ssh -t bob@foo "cd /tmp && exec $SHELL"
Or like this:
$ ssh -t bob@foo 'cd /tmp && exec $SHELL'
You can also do it this way, similar to @EvanTeitelman's solution:
$ ssh -t bob@foo "cd /tmp ; bash"
Or if you don't know the shell on the other end:
$ ssh -t bob@foo "cd /tmp && exec $SHELL"
Or like this:
$ ssh -t bob@foo 'cd /tmp && exec $SHELL'
answered Aug 16 '13 at 0:24
slm♦slm
256k71544690
256k71544690
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f86941%2fhow-to-ssh-into-a-specific-directory%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
-bash, ssh