Make Git Clone with Sudo

SSH KEY: sudo git clone permission denied

Since you were running git as root, presumably it tried to log in with root's ssh keys (if any), not yours.

Why does git needs sudo privileges to clone and if so, writes to root directory?

This is not Git, this is the install script for oh-my-zsh.

install.sh is trying to clone a repository. Where it installs is controlled by the ZSH environment variable. By default it will install into ~/.oh-my-zsh. If it went into /usr/share/oh-my-zsh you had ZSH set to that. You don't have permission to write to /usr/share. This is normal, a regular user should not have /usr/share permission.

When run with sudo (ie. with root permissions) it does have permission to write to /usr/share/oh-my-zsh, but sudo will clean up your environment variables so ZSH was not set for the command. It ran with its default ~/.oh-my-zsh. Normally sudo should preserve your home directory, but somehow it isn't and it's gone into root's home directory.


How to "fix" this depends on what you want. First, check what's in your environment with env | sort and make sure it's all correct.

If you just want to install the software for yourself, unset ZSH and run the installer. It will go into ~/oh-my-zsh.

If you want to install the software for everyone, download the script, use sudo and make setting ZSH part of the command.

cd /tmp
curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh
sudo ZSH=/usr/share/oh-my-sh sh -c install.sh


Related Topics



Leave a reply



Submit