tags:

views:

353

answers:

5

Is it possible to have an SSH session use all your local configuration files (.bash_profile, .vimrc, etc..) on login? That way you would have the same configuration for, say, editing files in vim in the remote session.

+5  A: 

No, because it's not SSH using your config files, but the remote shell.

I suggest keeping your config files in Subversion or some other VCS. Here's how I do it.

Andy Lester
I also store config files in an svn repository, but I checkout into a separate directory and then have a setup script to delete the original files and create symbolic links to the ones in the repo. That way I don't have to manually delete files.
marcog
+1  A: 

Well, no, because as Andy Lester says, the remote machine is the one doing the work, and it has no access back to your local machine to get .vimrc ...

On the other hand, you could use sshfs to mount the remote file system locally and edit the files locally. This doesn't require you to install anything on the remote machine. Not sure how efficient it is, maybe not great for editing big files over slow links.

Or Komodo IDE has a neat "Open >> Remote File" option which lets you edit files on remote machines by scping them back and forth automatically.

Sharkey
+1  A: 

ssh can be configured to pass certain environment variables through to the other (remote side). And since most shells will check some environment variables for additional settings to apply, you can hack that into applying some local settings remotely. But its a bit complicated and most administrators turn off the ssh environment variable pass-through in the sshd config anyways.

DragonFax
+2  A: 

Use a dotfiles.git repo

What I do is keep all my config files in a dotfiles.git on a central server.

You can set it up so that when you ssh into a remote machine, you automatically pull the latest version of the dotfiles. I do something like this:

ssh myhost
cd ~/dotfiles
git pull --rebase
cd ~
ln -sf dotfiles/$username/linux/.* .

Note:

  1. To put that in a shell script, you can automate the process of executing commands on a remote machine by piping to ssh.

  2. The "$username" is there so that you can share your config files with other people you're working with.

  3. The "ln -sf" creates symbolic links to all your dotfiles, overwriting any local ones, such that ~/.emacs is linked to the version controlled file ~/dotfiles/$username/.emacs.

  4. The use of a "linux" subdirectory is just to allow for configuration changes across platforms. I also have a mac directory under dotfiles/$username/mac. Most of the files in the /mac directory are symlinked from the linux directory as it's very similar, but there are some exceptions.

  5. Finally, note that you can make this even more sophisticated with hostnames and the like rather than just a generic 'linux'. With a dotfiles.git, you can also raid dotfiles from your friends, which is awesome -- everyone has their own set of little tricks and hacks.

ramanujan
A: 

You could always just copy the files to the machine before connecting with ssh:

#!/bin/bash

scp ~/.bash_profile ~/.vimrc user@host:
ssh user@host

This works best if you are using keys to login and no one else logs in as that user.

Chas. Owens