My password for sudo commands works on my Mac, but it doesn't work for su? How can I reset (or find) my su password?
I ask because I need to make my /data/db directory readable/writable for installing MongoDB and my sudo command isn't doing the trick. I was told to use su chmod 777 /data/db but the password is different from my sudo password.
sudo -s to get root, then passwd to change the root password. There might not be need to change the root password in your case; you can paste that command in after obtaining root via sudo -s.
Related
Why does sudo chmod <file> inside my shell script not work? The permissions stay as they were.
#!/bin/bash
sudo chmod 757 Folder
Remove the sudo from the file. Just write
chmod 757 folder
And give your script file +x permission. It will work.
In sudo visudo add this line to disable the request password when you write the sudo command:
www-data ALL=(ALL:ALL) NOPASSWD:ALL
Launch the script with the exec function and put sudo inside this with user root only. Now there's no need to enter a password.
exec("sudo -u root -S ./create_folders.sh)
I need to execute "monit restart haproxy" command after sudo su.
This is my script.sh
sudo su
monit restart haproxy.
Here if i will execute the script.sh file then it will hang and it is not executing the monit restart haproxy command.
Any idea?
The sudo command is expecting you to enter a password which is why it will hang, you can use a pipe so that the password is passed to the command like this:
echo <password> | sudo su
monit restart haproxy.
Here comes some information about sudo su. You need to enter password for sudo or su command, here is some quote from link i posted that may be the source of your problem:
sudo - sudo is meant to run a single command with root privileges. But unlike su it prompts you for the password of the current user. This user must be in the sudoers file (or a group that is in the sudoers file). By default, Ubuntu "remembers" your password for 15 minutes, so that you don't have to type your password every time.
hi i am using mac osx i tried to login sudo without password i followed this tutorial and edited this code in sudoers file
chmod +w /etc/sudoers
USERNAME ALL=(ALL) NOPASSWD: ALL
chmod -w /etc/sudoers
but now when i am trying to run any script with sudo command or trying to sudo -i its giving this error
user is not in the sudoers file. This incident will be reported.
this only user am using means its root user and i tried this also
MacBook-Air:~ exepaul$ sudo chmod +w /etc/sudoers Password: exepaul is not in the sudoers file. This incident will be reported.
so please help me ;(
for my instance , i just
su root
then enter self-define user password, then it switch to root!...
then i change root password to new one
I have installed proftpd file server using apt-get
But after adding User as shown below:
sudo useradd myproftpduser
sudo passwd myproftpduser
sudo usermod -m -d /var/www/ myproftpduser
and after restarting proftpd service I am not able to login with the new user.
I am able to login only with proftpd user.
Not sure where I am making mistake
The right way to create user in proftpd
sudo useradd myproftpduser -d /var/www/myproftpduser -s /bin/false
I used the following command in my script
sudo su - user -c bash <<EOF
cp /home/test.txt /opt/
EOF
If I use the sudo su - user on terminal, Unix don't ask me the Password but if I try to run the script the terminal ask me the Password and if I delete the EOF part the rest of code run when I quit the session.
I want to run the command in user mode sudo but the terminal don't Need ask me the Password.
If I use
sudo su - user <<EOF
code
EOF
I have an error in .bash_profile: too many argument
I want to run the command in user mode sudo but the terminal don't
Need ask me the Password.
The scenario you are experiencing is caused by the users cached credentials for sudo, which allow sudo to maintain a session and any further sudo command will not prompt for passwords.
Check this:
Open a new terminal and run sudo whatever, then close it and open another new terminal and run sudo whatever, you will see that sudo asks for password every time...
If you still need to do that, then you have the following options:
Prevent sudo to ask for password permanently:
run sudo visudo and look for the line root ALL=(ALL) ALL, then add a line
username ALL=(ALL) NOPASSWD: ALL
then save and exit.
Note: This is a security risk
Or Prevent sudo to ask for password permanently only for specific script:
run sudo visudo and look for the line root ALL=(ALL) ALL, then add a line
username ALL=NOPASSWD: path_to_the_script
then save and exit
Provide password inside the script, by running your sudo command like this:
sudo -S <<< "password" command
Note: This is a security risk too.
I guess you need to execute your command as a different user. This might be your answer: Run a shell script as another user that has no password
sudo -H -u otheruser bash -c 'echo "I am $USER, with uid $UID"'
It is a quote from the link. Probably the following is better for you:
sudo -H -u otheruser bash <<EOF
cp /home/test.txt /opt/
EOF
UPDATE: You may wish to create a specific sudo rule to run a specific command without password (inside /etc/sudoers file -remember to use visudo to edit it-):
otheruser ALL=NOPASSWD: /full/path/to/your_command.sh
(of course you need root access to edit sudoers, I hope you can do it).
And create the script called your_command.sh that contains your logic. You'll then be allowed to run it without password:
sudo -H -u otheruser your_command.sh
I know, it's not a "single line command" but it is safe as it allows only one specific command without password. And it doesn't require a password, of course!
Then don't use sudo, then it won't ask for password, but you will to be have logged in as root!