0

I have a board with the default shell being sh. At the end of "/etc/profile" there is:

exec /bin/ash

This changes the shell to ash.

What should I do if want to execute a file where I defined some aliases in ash?

I tried using:

exec /bin/ash -f /root/aliases.sh

But when I login to the board using ssh it exits saying connection closed.

Any other way?

kos
  • 35,535
  • 13
  • 101
  • 151
Ramana Reddy
  • 761
  • 2
  • 14
  • 25

1 Answers1

1

When you run exec /bin/ash -f /root/aliases.sh ash runs non-interactively, and it exits as soon as "/root/aliases.sh" has been executed; that's why the SSH session ends.

So the solution is to run the shell interactively; from man 1 ash:

If the environment variable ENV is set on entry to a 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 shell inside the ENV file.

So just set ENV in "~/.profile":

export ENV=/root/aliases.sh

and run the shell interactively:

exec /bin/ash

However notice that:

  1. Running exec /bin/ash at the end of "~/.profile" will replace any shell sourcing "~/.profile" (i.e. any login shell) with an ash instance;
  2. This makes no sense. The correct way to get ash as a login shell for an user is to change the login shell for the user, which can be done using chsh.

So I really suggest you to remove exec /bin/ash from "~/.profile" and to change the login shell for the user using chsh instead.

kos
  • 35,535
  • 13
  • 101
  • 151