I have an ASP.NET Core 5 web app running on Linux (Apache) which is working fine in general. I want it to be able to change passwords of certain Linux users. Basically the user logged into the web app can change their corresponding Linux password, which they use for SFTP.
I can run ssh/bash commands from the web app but they are run using the user www-data
I'm not sure what the best way of doing this is:
- Try to start a new SSH session all together as a user with sudo rights. (I'm not sure how to do that though.
- Use sudo with the www-data user (seems less secure as it increases permissions for anything else using the www-data user).
Running a command like this does work to change a user's password as long as there are root permissions:
echo -e "changeme2\nchangeme2" | passwd testuser1
Thanks for any advice.
Thanks @feihoa, I did end up using SSH.NET to create a SSH session to localhost and do what I needed to.