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:
- Running
exec /bin/ash at the end of "~/.profile" will replace any shell sourcing "~/.profile" (i.e. any login shell) with an ash instance;
- 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.