Answer the question
In order to leave comments, you need to log in
How to log in with a different username in a bash script?
I make a clean server configuration script for my needs:
USER='user'
PASS='555'
sudo useradd -G sudo -m -d /home/$USER --password $(echo "$PASS" | openssl passwd -1 -stdin ) $USER
apt update
apt install mc sqlite ncdu htop git nload curl zip tmux python3-pip -y
login -p user # Как передать сюда пароль 555?
pip3 install bs4 lxml requests
login -p user
Answer the question
In order to leave comments, you need to log in
sudo su -l user -c 'pip3 install --user bs4 lxml requests'
One of the options:
su -l user -c 'pip3 install bs4 lxml requests'
sudo can accept password from stdin, option
-S, --stdin
Write the prompt to the standard error and read the password from the standard input instead of using the terminal device.
but this is not secure, it is more correct to write the necessary line for launching the program without asking for a password in /etc/sudoers
articles in bulk, for example https://losst.ru/otklyuchaem-parol-sudo-v-linux
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question