The situation:

I run Ubuntu 12.04 LTS on a virtual machine.

I regularly have to connect to my account on a university server, I do this by opening up terminal and using ssh -Y username@server.com.

Once there I always have to run the following

setenv PYTHONPATH "place/stuff/this_goes_on_forever"

And also a few other lines of code.

What I want:

  1. My main request: I would like to prepare a script and have that run automatically whenever I log in to the server via ssh.

  2. This is a side query, but when I use alias p="pwd" (for example) the new aliases do not 'take', typing p in this case results in 'command not found'. Is this just a consequence of not being root, or because I am logged in via ssh, or is there a fix for this perhaps?

Attempts at a solution:

I tried adding export PYTHONPATH="..." to my local ~/.bashrc file which means when I start terminal PYTHONPATH is set, however after I ssh to the server it is no longer set (well I have a whole new host of environment variables). I tried ~/.bash_profile after, didn't work.

I have tried adding export PYTHONPATH="..." to the ~/.bash_profile file on the server, and also to the ~/.bashrc file- but neither worked.

I do not have root access on the server so cannot change AcceptEnv or PermitUserEnvironement within the sshd_config file on the server, it is just read-only.

Surely there is somewhere I can put this code, I just can't find where.

  • What shell do you run on the remote server? Connect to the server and run echo $0. – terdon Nov 14 '13 at 14:32
  • echo $0 returns -tcsh – Marchy Nov 15 '13 at 16:56
  • OK, then see my answer. You should add setenv PYTHONPATH "place/stuff/this_goes_on_forever" to ~/.tcshrc on the remote server. You can also use cssh on the server to change your default shell. – terdon Nov 15 '13 at 17:01
  • chsh :) doesn't work since system admin has blocked it for non-root users. All problems now solved, just need to modify ~/.tcshrc and when defining aliases use the correct syntax for tcsh/csh. Many thanks – Marchy Nov 15 '13 at 17:20
  • 1
    Damn, same typo both times... It just means CHange SHell and I still get it wrong :). – terdon Nov 15 '13 at 17:21

There are two things to consider here:

  1. It sounds like you are not using bash on the remote server so your .bashrc and .bash_profile will not be read.

  2. ssh starts a login shell on the remote server so even if you were running bash, .bashrc would not be read. That file is only read by interactive, non-login shells.

Many login shells, however, read ~/.profile. I can't be sure since you have not mentioned which shell you are using but chances are that if you add this line to your ~/.profile file (on the remote server) you'll get your variable set:


Since you are running tcsh, the startup files are different. From man tcsh:

   A login shell begins  by  executing  commands  from  the  system  files
   /etc/csh.cshrc  and  /etc/csh.login.   It  then  executes commands from
   files in  the  user's  home  directory:  first  ~/.tcshrc  (+)  or,  if
   ~/.tcshrc  is not found, ~/.cshrc, then ~/.history (or the value of the
   histfile shell variable), then ~/.login, and finally ~/.cshdirs (or the
   value  of  the  dirsfile  shell  variable)  (+).   The  shell  may read
   /etc/csh.login before instead of  after  /etc/csh.cshrc,  and  ~/.login
   before  instead  of  after  ~/.tcshrc or ~/.cshrc and ~/.history, if so
   compiled; see the version shell variable. (+)

So, you should add your setenv command to ~/.tcshrc on the remote server.

Finally, since it sounds like you are more used to bash, why don't you change the shell you use on the remote server? Just log in to the server and then run


Give it /bin/bash as your default shell and all these problems go away. You will then be able to set variables and aliases as you would expect, by editing ~/.profile or ~/.bash_profile on the remote server.

  • Hi, echo $0 when logged on to the server returns -tcsh. Also man csh returns the csh documentation so I think that must be what the server runs. I have created ~/.cshrc and added the code to that, and it works! Thank you :D As side note: I tried running cssh and it returned command not found. – Marchy Nov 15 '13 at 17:03
  • @Marchy my bad, that should be chsh not cssh. – terdon Nov 15 '13 at 17:04
  • Thanks :) chsh has been disabled for non-root users by system admin, but I'm quite happy learning the ways of a new shell – Marchy Nov 15 '13 at 17:12
  • This also solves my problem with aliases since the syntax is different in csh/tcsh when using alias. – Marchy Nov 15 '13 at 17:18

It looks like you are using csh on the server, add your code to the csh start up there. csh has a slightly different syntax than bash to set aliases, do a man csh on your server for information.

  • It IS running csh, I've now added the code to ~/.cshrc. Thanks :) – Marchy Nov 15 '13 at 17:04

Test which shell you are using by running:

echo $SHELL

If it is bash, and it is not automatically reading ~/.bashrc, you may need to create a ~/.bash_profile file.

$ cat .bash_profile 
if [ -f ~/.bashrc ]; then
    . ~/.bashrc

Regarding this:

I tried ~./.bash_profile after, didn't work.

If you meant that you were trying to source the profile file, that syntax is wrong. To source an environment file, run this:

. ~/.bash_profile
  • echo $SHELL does not print the shell you are currently using. It prints the default shell which is not necessarily the same. Try running a different shell and echo $SHELL. – terdon Nov 15 '13 at 17:03
  • Hi, that was a typo as regards ~/.bash.profile :S thanks though :) [now edited the original question] – Marchy Nov 15 '13 at 17:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.