Score:2

How do I open a terminal with another user name?

id flag

Whenever I open the terminal, I want to login as another user (another_user). I tried putting the below in my .bashrc, but it prompts me for a password everytime I open the terminal.

# in .bashrc
su - another_user

Question: how do I pass another_user's password as a text input in .bashrc so that I don't have to type it every time the terminal opens?

PS: don't worry about security issues.

Thanks.

ar flag
Which distro and version of Linux are you using?
cocomac avatar
cn flag
Also... wouldn't it be easier to sign in as them? It seems a bit strange to sign into you, only to instantly sign in as them... perhaps you have [an XY Problem](https://meta.stackexchange.com/q/66377/1081494)?
id flag
@user68186 Ubuntu 21.10, Kernel version: 5.13.0.
id flag
@cocomac, I appreciate your suggestion but that doesn't answer my question.
Score:1
id flag

The below worked for me:

echo 'password_text' | sudo -S sleep 1 && sudo su - another_user

thanks!

Source: https://superuser.com/questions/1351872/how-to-provide-password-directly-to-the-sudo-su-someuser-in-shell-scripting

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.