0

I work on a ubuntu server and I don't have the root permission. The default shell is dash. When I try to change the default shell,it tells me it don't have permission.

user@host:~$ chsh -s "which zsh"
You may not change the shell for 'binjie'.

The permission issue cannot be solved, so I turn to ~/.profile to run bash every time I log in. When I add echo something to ~/.profile, it is executed. But when I add exec -c bash to ~/.profile, after I logged in via SSH the shell lost response. After I clicked Ctrl-C the connection was closed. I'm very confused. Can anyone help?

chepner
  • 497,756
  • 71
  • 530
  • 681
nanimonai
  • 73
  • 6
  • 3
    Sounds like bash is reading `~/.profile` too and getting into an infinite loop. Create a `~/.bash_profile` for it to override – that other guy Oct 20 '18 at 16:20
  • `exec`, at least in `dash`, doesn't take any arguments. What is the `-c` supposed to mean? – chepner Oct 20 '18 at 16:21
  • Thanks very @that-other-guy! Now I understand where the problem comes. I'm just used to adding a `-c` in bash @ chepner – nanimonai Oct 21 '18 at 03:14

1 Answers1

2

Ok I find the solution in dash manual:

A login shell first reads commands from the files /etc/profile and .profile if they exist. If the environment variable ENV is set on entry to an interactive shell, or is set in the .profile of a login shell, the shell next reads commands from the file named in ENV. Therefore, a user should place commands that are to be executed only at login time in the .profile file, and commands that are executed for every interactive shell inside the ENV file. To set the ENV variable to some file, place the following line in your .profile of your home directory ENV=$HOME/.shinit; export ENV substituting for ''.shinit'' any filename you wish.

But still could anyone explain to me why adding exec -c bash directly to .profile won't work?

nanimonai
  • 73
  • 6
  • 1
    See @thatotherguy's comment. `bash` is also reading `.profile`, so as part of its startup it replaces itself with `bash`, which reads `.profile` and replaces itself with `bash`, which ... It's just an infinite loop of shells restarting. `ENV`, on the other hand, is not used by `bash` if it isn't invoked as `sh`. – chepner Oct 20 '18 at 18:51
  • 1
    I added `exec fish` at the end of .profile and it works perfectly. (Ubuntu 20, WSL) – tejasvi88 Apr 06 '22 at 05:45