can't add value with sharp sign in environment variable

I need set a password to environment variable but the problem is password include sharp sign and when i want use this variable just show me till first sharp sign. for example assume he#l#lo is my password and when i set it to /etc/environment with PASSWORD_API="he#l#lo" then i print it just show he and leave the character after # . but when i using export PASSWORD_API="he#l#lo" from terminal all if fine!what is problem by adding environment variable from \etc\environment i can't change the password so if you have any idea please help me . thank you


As far as I can tell, this is a limitation of how the pam_env module reads lines of the environment file (before even attempting to parse them into name=value pairs).

Specifically, in the _pam_assemble_line function (in libpam/pam_handlers.c):

        /*
         * we are only interested in characters before the first '#'
         * character
         */

        while (*s && *s != '#')
             ++s;

There appears to be no provision for treating quoted or escaped strings any differently.

If you need to set an environment variable with such characters, then you will need to do it elsewhere - for example, creating a file /etc/profile.d/password-api.sh containing the line

export PASSWORD_API="he#l#lo"

which should get sourced by the default /etc/profile.


Of course as I'm sure you're aware, storing passwords ANYWHERE in plain text is a bad idea - if your application provides another option (such as using key-based authentication, or adding the password securely to an agent) you should use it.