Change default terminal shell to root - bash

I was experimenting with my root user on macOS, and performing a zsh installation for the root user and now I can not access my root user. When wanting to enter the school
sudo su
The console returns the following message, and I do not know how to fix this problem.
"su: /usr/bin/zsh: No such file or directory"

The error message tells you, that for the user root the default shell is configured to be /usr/bin/zsh and su is trying to start this programm, but it is not there.
You can do a
sudo /bin/bash
to get a root shell and fix your problem. Either copy your zsh to the right location or change the shell for root back to the default. on my mac it is "/bin/sh"

If you don't have zsh installed on mac, try this:
brew install zsh

Related

run inline shell script as root

I have a user, who's a passwordless sudoer. I need to execute shell script file with him, and make him execute one block as sudo. E.g:
su root <<"AS_ROOT"
# do something with my linux
AS_ROOT
But nothing works. I tried:
su - root <<...
sudo -s -- <<...
It barks back at me. I'm on ubuntu 16.04 lts.
Thank you.
As Cyrus points out, su is a different utility to which sudo's configuration doesn't apply.
It sounds like you're looking for something like this:
sudo -s <<'AS_ROOT'
echo "Hi from $USER."
AS_ROOT
This should output Hi from root.
Note that -s is needed to tell sudo to create a shell in order to interpret the commands passed via stdin (the here-doc). That shell is the current user's default shell, as reflected in environment variable $SHELL.

How disable need to sudo? Setting root to admi, sudivo, and disabling SIP didn't work

I am having to type "sudo" before most terminal commands, and am also getting EACCES errors sometimes even when using sudo when chained to a secondary file/folder.
I've done the standard setting of root user to admin, added my username with all permissions in visudo, and successfully disabled SIP. It may have to do with permissions I may have changed when I first got my Mac years ago.
Does anybody have any ideas as to what could be wrong?
Sometimes you use sudo command1, you also encountered permission denied. It's because the command1 will invoke another process which don't have root prividge. In this situation you can put command in a script, and use sudo bash script, or su to change to root user. And sometimes sudo filename also permission denied, it's that you not have the x priviledge, you can sudo chmod 744 filename, then execute the command.
methods to avoid type sudo passward every minutes.
method 1 recomended. sudo -i
method2 use sudo visudo or sudo vim /etc/sudoers and put this in it. this will make username user neednot to pass passward when use sudo.
username ALL=(ALL) NOPASSWD: ALL
you can refer here for config for one command
hope helps.
Log in and open your terminal app. Run these two commands:
sudo echo >> /etc/sudoers
sudo echo "$(id -u -n) ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
Now you can run sudo without a password. Do normal stuff under your regular account and when you want to run as root for a while do:
sudo bash
macOS includes a "root user" that can be enabled using Directory Utility. Have a look at the following article from Apple: Enabling and using the "root" user in OS X. The article, while not explicitly saying it, implies that using the root user is the same thing as sudo.
The Apple article includes some warnings about use of the root user, but if you think about it, it's no more risky than deliberately disabling the password required by sudo. Either way you're creating an unrestricted path to root-level functions, so do be careful about it!
None of these solutions worked as things are. Ended up wiping my computer's hard drive and permissions settings went back to normal.

Stardog server start with license key : wrong STARDOG_HOME

I'm on MAC OSX. I added these lines in my ~/.bash_profile :
PATH="/usr/local/stardog/bin:${PATH}"
export STARDOG_HOME=/data/stardog
export PATH
Then, in command line, I execute
cp stardog-licence-key.bin $STARDOG_HOME as the quick-start documentation states.
But, this seems useless, because when I execute sudo stardog-admin server start, it says :
A Stardog license was not found.
The license file 'stardog-license-key.bin'
should be in your Stardog Home directory 'xx/xx'.
xx/xx is the current directory when I launch this command ... but stardog home directory is supposed to be /data/stardog, not my working directory !
How to tell stardog his actual home directory ?
Fine (and sorry), I did not mention some elements : I executed the command stardog-admin server start with sudo (as seen in the last edit of my question).
Reasons :
I launched this command with sudo because I needed some permissions to start stardog properly.
Problem : With sudo, stardog home is not the one defined in my previous .bash_profile anymore.
Solution : I give (owner) permissions to myself on the directory $STARDOG_HOME with the command sudo chown -R myUsername /data/stardog
Open a new bash, type stardog-admin server start without sudo, it works.

How do I run a shell script with administrator privileges through AppleScript without prompting for a password?

I want to have my AppleScript application run a Python script with sudo, but I don't want the application to prompt the user for a password (our users do not have sudo privileges).
The Python script has been added to the /etc/sudoers file appropriately (ALL ALL=NOPASSWD: /path/to/script.py). In the terminal, I can do (as a regular, non-privileged user):
$ sudo ./script.py
and it runs perfectly well. But in AppleScript when you try to do:
do shell script "sudo ./script.py"
You of course get the "sudo: no tty present and no askpass program specified" error. But if you change it to:
do shell script "./script.py" with administrator privileges
AppleScript insists on presenting a popup window to ask for the password. I have also tried passing a null password to sudo with a pipe:
do shell script "echo '' | sudo -S ./script.py"
but that also does not work. (I think it tries to run sudo individually first and then pass the command through, which won't work because the user doesn't have sudo privileges!)
I need a solution where AppleScript will run the Python script with sudo. I would prefer the script stays unreadable and un-executable by average users for security reasons, and is only executed through the AppleScript. (I know that, hypothetically, the users could call sudo script.py and it would run, but that's assuming they even know about sudoers; I'm trying to keep it as secure as possible while still usable).
I'm still pretty new to AppleScript, so any help would be greatly appreciated! Thanks!
When I added ALL ALL=NOPASSWD: /Users/myusername/a to sudoers and ran echo $'#!/bin/bash\nsay $(ls ~root|head -n1)'>~/a;chmod +x ~/a, do shell script "sudo ~/a" ran the script as root without requiring a password.
I'm guessing the problem is that you specified the path like do shell script "sudo ./script.py". Try to use do shell script "sudo ~/script.py" instead. The default working directory is for do shell script is / and not ~/.

Capistrano :shell example

I'm currently using Capistrano to deploy my web application which works like a charm.
In my new project I must execute a command from sudo /bin/bash shell.
Is it possible for Capistrano to login to the machine as user X, run sudo /bin/bash,
enter the password and then execute a command in the sudo shell? If yes, could you
please provived me with an example.
With regards
jakob
Is there a specific reason you need to be in a root shell rather than executing the command with sudo? If executing a command with sudo, you can simply sudo 'command' instead of run 'command'.
I did a little experimentation to try to get a root shell with capistrano without logging into the server directly as root, and wasn't able to make much progress.
If running with sudo won't work, please update your question to let us know why and maybe we can help you find a workaround for it.
Update:
After playing around a little more, I found that you can execute an individual command (or string of commands) in a root shell by doing something like sudo '/bin/bash -c "whoami"'. It's getting an interactive root shell that's tricky.

Resources