Change group with chown in OSX - macos

Trying to change the group for a file on OSX to root, keep getting an illegal group name error though.
Looked around and all the demos match what I'm using. Am I missing something here?
Tried to create a group with dscl as well with the same result
Command: dscl . -create /Groups/root
Command: sudo chown root:root $file
Error: chown: root: illegal group name

When I had this issue (macos 10.12.x) I needed one final command for the initial command to work and no longer throw the
illegal group
error.
dscl . -create /Groups/groupName GroupMembership userName
I had done the PrimaryGroup command which didn't work until the command above was added.

Related

How to delete user via terminal

I'm having some issues installing Postgres and have been trying a few different approaches. I eventually followed this approach which meant I had to run the following command in terminal...
sudo dscl . -create /Users/postgres UserShell /bin/sh
sudo dscl . -create /Users/postgres NFSHomeDirectory /Library/PostgreSQL
However, this did not resolve issue I'm having with installing Postgres.
I then attempted to added postgres users via system preference but ran into the error of "Name already used by another user". However I cannot see this users!
.
How can I effectively delete the postgres user created in the above command? The goal is to add the users via system preferences instead.
I can see the hidden user by using this command:
dscl . -list /Users
I figured it out.
sudo /usr/bin/dscl . -delete "/Users/postgres"

jenkins build failure shell command permission denied

I am trying to run shell build command on mac but I get permission denied for e.g. ls /Users/... command.
I see whoami is jenkins, which is different for my uesr login?
I read online I need to run chmod for jenkins user, how do I do that?
I changed file permission using chmod 777?
Do I need to change jenkins user?
In linux, e.g. ubuntu, you can add user jenkins to the root group:
sudo usermod -a -G root jenkins
Then restart jenkins:
sudo service jenkins restart
Be aware that, adding jenkins user to root group can make the user too powerful, use with caution
Maybe you have a problem that jenkins is not a full user. Try this:
Create a user for Jenkins
It’s best to run Jenkins as it’s own user (it can then be limited in the permissions it has), and you’ll want to create a standard (full) user for it.
You can do this through System Preferences, the Server Manager or the command line.
For a local user:
# create an applications group
dseditgroup -o create -n . -u username -p -r ‘Applications’ applications
# get the id for that group
sudo dscl . -read /Groups/applications
# find a unique identifier to give the user
sudo dscl . -list /Users UniqueID
# create the jenkins user
sudo dscl . -create /Users/jenkins
sudo dscl . -create /Users/jenkins PrimaryGroupID 505
sudo dscl . -create /Users/jenkins UniqueID 1026
sudo dscl . -create /Users/jenkins UserShell /bin/bash
sudo dscl . -create /Users/jenkins RealName "Jenkins"
sudo dscl . -create /Users/jenkins NFSHomeDirectory /Users/jenkins
sudo dscl . -passwd /Users/jenkins
# create and set the owner of the home directory
sudo mkdir /Users/jenkins
sudo chown -R jenkins /Users/jenkins
I found this here: installing jenkins on OS X Yosemite
In my case, the folder was inside a NFS/Samba/Webdav share, which these scripts seem not able to handle.
I created a real folder in my fs and linked it to a subdir in the shared folder. That way, no permission denied errors occur anymore.
Jenkins user won't have permissions to run a non jenkins user folders or files. Use either to run as some other user in the shell (assuming linux OS) or copy the folders or contents to jenkins default folder.
sh '''
su - - << EOF
Commands to run
'''
OR
copy folders to jenkins default folder
cp -rp <folder/files/related scripts to run> </usr/lib/jenkins/>
open terminal
sudo nano /etc/sudoers
at the end of the file add the following statements:
Jenkins ALL=(ALL) NOPASSWD: ALL
Save and exit
I had the same issue in Windows, where the only user is tadmin and Jenkins running from CMD with elevated/admin privileges.
I am using "content replace plugin" - it runs only once and after that says the file is locked, however Unlocker and other utils do not show anything and yet I cannot delete or rename that file. Restarting Jenkins service and reloading did not help, file was still locked. Only a reboot released the file.
It ended up by using powershell plugin to change content of the file - this runs without issues (some tweaking needed to use jenkins variables and double quotes)
For example, to replace 'img src' -> 'img title="branch, build..." src'
powershell -Command "(gc ad/bootstrapheader.jsp) -replace 'img src', 'img title=""""branch: $env:GIT_BRANCH; build: $env:BUILD_ID"""""" src' | Out-File ad/bootstrapheader.jsp"

BASH chown command not executing from script: illegal group name

I execute the script below as root within MAC OS X terminal. The piped command runs successfully, but the script fails at the chown command with the following error:
chown: Domain Users: illegal group name
Why?
See script below:
#!/bin/bash
echo Enter username
read Name
echo Enter number
read NUM
sudo -s "(cd /Users/$NAME && tar c .) | (cd /Users/$NUM && tar xf -)"
sudo chown -R $NUM:"Domain Users" /Users/$NUM
sudo chmod g+rwx /Users/$NUM
"Domain Users" is an Active Directory group, hence one must be connected to the domain in order to CHOWN against a specified user within this group and take ownership of the resources specified. I was working remotely this day and was not connected via our VPN, hence not connected to our domain and thus unable to CHOWN against this Active Directory group "Domain Users".
Your reading the variables wrong:
should look like this:
...
read NAME
....
read NUM

Subversion on Mac -- unable to commit files

I recently set up an svn server on Mac OS X. I am able to checkout files, but not commit, with the error:
Error Can't open file '/usr/local/repo/db/txn-current-lock': Permission denied
I understand this is an ownership issue -- however, I've tried various solutions I've found from searches such as:
chown -R subversion:subversion /usr/local/repo
But I get that subversion is an invalid argument (probably because there is no user or group on my machine with these names). My issue is -- how do I create these users and a group so that are linked with the user names and passwords specified in my svn authentication file?
Thanks!
Andrew
I think this surely is a permissions problem:
As I dont know the user and the group here, so what i would suggest is using:
sudo chown -R $(id -u):$(id -g) /path/to/repo #now new owner would be current user and the group wold become current usergroup.
chmod -R u+w /path/to/repo

Run daemon as another user on mac os x

I'm trying right now to create separate user for jenkins on Mac Os and run it with this user.
I've created a new user:
# Create the group
sudo dscl . create /Groups/jenkins
sudo dscl . create /Groups/jenkins PrimaryGroupID 300
# Create the user
sudo dscl . create /Users/jenkins
sudo dscl . create /Users/jenkins PrimaryGroupID 300
sudo dscl . create /Users/jenkins UniqueID 300
sudo dscl . create /Users/jenkins UserShell /bin/bash
# Set the users pasword
sudo dscl . passwd /Users/jenkins 123qweASD
# Add the user to the group
sudo dscl . append /Groups/jenkins GroupMembership jenkins
And the I try to run jenkins as jenkins user:
sudo su - jenkins -c run_jenkins.sh
and got an error:
su: no directory
after I created directory for jenkins user:
sudo dscl . -create /Users/jenkins NFSHomeDirectory /Users/jenkins
followed next error:
su: unknown login: jenkins
General quiestion:
How can I create an _www like user for a daemon, without home directory i.e.
How can I run a script as this new user.
Thanks for help!
man launchd.plist
UserName <string>
This optional key specifies the user to run the job as. This key is only
applicable when launchd is running as root.
GroupName <string>
This optional key specifies the group to run the job as. This key is only
applicable when launchd is running as root. If UserName is set and Group-
Name is not, the the group will be set to the default group of the user.
You may need to use the absolute of run_jenkins.sh (assuming its /Users/jenkins/run_jenkins.sh):
sudo su - jenkins -c /Users/jenkins/run_jenkins.sh
su - emulates a normal login, and hence requires that the account be set up for regular logins (have a shell and home directory defined, etc). Unless you need this for some reason, just let sudo do it:
sudo -u jenkins run_jenkins.sh

Resources