Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Switch user in a terminal window on a Mac

Could anybody help with simple question. I need login/switch user in command line in 1 line; For example: login -p username ? password.

What should I write at '?' position? Because I need to login in script which don't know id system asked password...

like image 473
user633101 Avatar asked Apr 15 '11 00:04

user633101


2 Answers

You could try to use

su - username

in order to switch to the user you want.

You can find more documentation about su command here

like image 174
ppolyzos Avatar answered Oct 04 '22 21:10

ppolyzos


You can provide the password to sudo like this:

echo "p@sw0rd" | sudo -S cal -y 2011

The example above runs 'cal -y 2011' with root permissions.

like image 27
Anne Avatar answered Oct 04 '22 21:10

Anne