LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 07-20-2011, 12:29 AM   #1
hydraMax
Member
 
Registered: Jul 2010
Location: Skynet
Distribution: Debian + Emacs
Posts: 467
Blog Entries: 60

Rep: Reputation: 51
SSH into particular directory: problems


So, I wanted to give myself a short cut to not just login to a remote server, but also change into a particular directory once I got there. This was harder than I expected, but this finally worked when I wrapped this up into a short cut:

ssh -t user@example.com 'cd /var/www/mydir; bash'

And I just alter the directory path to make another shortcut to a different place on the same server.

This does work, however, it seems when I log in this way, some of my environment is lost, and my locale is set back to the default "POSIX". That's not good. What's going on here and how should I fix it?

I'm running Gentoo Linux (amd64).
 
Old 07-20-2011, 12:54 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
You could try
Code:
ssh -t user@example.com 'bash --rcfile ~/.my_cd'
and create ~/.my_cd with
Code:
source ~/.bashrc
cd /var/www/mydir
Depending on which bash initialisation file you want to use, change the source ~/.bashrc line as required.
 
Old 07-20-2011, 11:13 PM   #3
hydraMax
Member
 
Registered: Jul 2010
Location: Skynet
Distribution: Debian + Emacs
Posts: 467

Original Poster
Blog Entries: 60

Rep: Reputation: 51
Quote:
Originally Posted by catkin View Post
You could try
Code:
ssh -t user@example.com 'bash --rcfile ~/.my_cd'
and create ~/.my_cd with
Code:
source ~/.bashrc
cd /var/www/mydir
Depending on which bash initialisation file you want to use, change the source ~/.bashrc line as required.
Thanks... a bit more complicated than ideal, but it seems to work fine. I replaced your source ~/.bashrc with source /etc/profile which in my distro gets the global environment settings.
 
Old 07-21-2011, 12:01 AM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by hydraMax View Post
Thanks... a bit more complicated than ideal, but it seems to work fine. I replaced your source ~/.bashrc with source /etc/profile which in my distro gets the global environment settings.
Glad it worked for you

Probably /etc/profile has already been sourced in which case the line is not required. AIUI, the file named after --rcfile is the functional equivalent of .bashrc

Threads can be marked SOLVED via the Thread Tools menu.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ssh could not chdir to home directory pccdrussell Linux - General 27 08-24-2012 10:30 AM
ssh authorized keys from one directory to another directory did not worked tkmsr Linux - Software 4 10-25-2010 08:28 AM
Could not create directory ssh solution....? bianchi77 Linux - Server 5 05-02-2010 01:48 PM
Create Directory? ssh/svn help WestsideGuy Linux - Newbie 2 07-23-2008 03:28 PM
ssh to different directory other than home pridefc Linux - Software 5 11-17-2006 06:12 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 11:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration