Originally posted by: AncientAIXer
Loading .profile only occurs when a login shell is started. ssh allows commands to run without opening a shell. But there may be ways of doing what you are wanting to do. Also, ssh is flexible enough that no matter what you do on the server end, a user might be able to circumvent it with the client options. I have not personally tried these, but there are several sshd configurations/options you might look into.
1) The use of /etc/ssh/sshrc:
Similar to ~/.ssh/rc, it can be used to specify machine-specific
login-time initializations globally. This file should be
writable only by root, and should be world-readable.
If you put the sourcing of .profile in this file, the user can still manipulate his/her .profile to circumvent some settings. For more security, the options should be set in the file.
2) Use of the ForceCommand option:
Forces the execution of the command specified by ForceCommand,
ignoring any command supplied by the client and ~/.ssh/rc if
present. The command is invoked by using the user's login shell
with the -c option. This applies to shell, command, or subsystem
execution. It is most useful inside a Match block. The command
originally supplied by the client is available in the
SSH_ORIGINAL_COMMAND environment variable. Specifying a command
of internal-sftp will force the use of an in-process SFTP server
that requires no support files when used with ChrootDirectory.
The default is none.
This might not allow a "remote command" and only allow interactive shells, or it may only allow the command specified to be executed. You'll have to try it to find out. I have run across references to a SSH_ORIGINAL_COMMAND variable in connection to this option and making a wrapper script, so you might want to research that as well.