Installing Git with Non-Root User Account

Installing Git with non-root user account

You can download the git source and do ./configure --prefix=/home/user/myroot && make && make install to install git to your home directory provided you have the build tools. If you don't have the build-essential package installed (dpkg --list|grep build-essential), you will need to install those to your home directory as well.

Install Git without sudo privilege

This will be not very easy to have something working if dependencies are missing.

What you can do, download the .deb to get the last git version, you can find it https://debian.pkgs.org/11/debian-main-amd64/git_2.30.2-1_amd64.deb.html

For example:

cd /tmp
wget http://ftp.br.debian.org/debian/pool/main/g/git/git_2.30.2-1_amd64.deb

Then extract it

mkdir git
cd git
ar x ../git_2.30.2-1_amd64.deb

You will get

total 5.3M
drwxrwxr-x 2 john doe 4.0K Oct 29 21:31 ./
drwxrwxrwt 29 root root 16K Oct 29 21:31 ../
-rw-r--r-- 1 john doe 16K Oct 29 21:31 control.tar.xz
-rw-r--r-- 1 john doe 5.3M Oct 29 21:31 data.tar.xz
-rw-r--r-- 1 john doe 4 Oct 29 21:31 debian-binary

Then extract the data part:

tar xvf data.tar.xz

and you get the binaries

╰┤suze ▶ ls -l usr/bin
total 4968
-rwxr-xr-x 1 john doe 3343280 Mar 10 2021 git*
lrwxrwxrwx 1 john doe 3 Mar 10 2021 git-receive-pack -> git*
-rwxr-xr-x 1 john doe 1733608 Mar 10 2021 git-shell*
lrwxrwxrwx 1 john doe 3 Mar 10 2021 git-upload-archive -> git*
lrwxrwxrwx 1 john doe 3 Mar 10 2021 git-upload-pack -> git*

How to install Git on Linux without admin rights (locally)


  1. Download the source code to your home directory and unzip it.

  2. Some dependency libraries are optional and can be disabled. The following will disable all of them. You may try disabling the ones you are missing and see if your installation succeeds.

.

make prefix=~/local/git NO_PERL=YesPlease NO_OPENSSL=YesPlease NO_CURL=YesPlease NO_TCLTK=YesPlease NO_EXPAT=YesPlease NO_GETTEXT=YesPlease
make prefix=~/local/git NO_PERL=YesPlease NO_OPENSSL=YesPlease NO_CURL=YesPlease NO_TCLTK=YesPlease NO_EXPAT=YesPlease NO_GETTEXT=YesPlease install

Can I run docker without root in github actions?


    && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
&& chmod 0440 /etc/sudoers.d/$USERNAME ```

Those two lines defeat the entire reason for not running your container as root. It's a passwordless escalation to root making the user effectively the same as having full root access.

docker run -u dev -v $PWD:/home/dev/project project /bin/bash -c
"./my_script.sh"

but my_script.sh fails to create a directory with permission problems.

Host volumes are mounted with the same uid/gid (unless using user namespaces). So you need the uid/gid of the user inside the container to match the host directory uid/gid permissions.

I also tried docker run -u $USER ... but it does not find the user
runner inside the container.

If you specify a username, it looks for that username inside the container's /etc/passwd. You can instead specify the uid/gid like:

docker run -u "$(id -u):$(id -g)" ...

Make sure the directory already exists in the host (which will be the case for $PWD) and that the user has access to write to that directory (which it should if you haven't done anything unusual in GHA).

Change the location of the ~ directory in a Windows install of Git Bash

I don't understand, why you don't want to set the $HOME environment variable since that solves exactly what you're asking for.

cd ~ doesn't mean change to the root directory, but change to the user's home directory, which is set by the $HOME environment variable.

Quick'n'dirty solution

Edit C:\Program Files (x86)\Git\etc\profile and set $HOME variable to whatever you want (add it if it's not there). A good place could be for example right after a condition commented by # Set up USER's home directory. It must be in the MinGW format, for example:

HOME=/c/my/custom/home

Save it, open Git Bash and execute cd ~. You should be in a directory /c/my/custom/home now.

Everything that accesses the user's profile should go into this directory instead of your Windows' profile on a network drive.

Note: C:\Program Files (x86)\Git\etc\profile is shared by all users, so if the machine is used by multiple users, it's a good idea to set the $HOME dynamically:

HOME=/c/Users/$USERNAME

Cleaner solution

Set the environment variable HOME in Windows to whatever directory you want. In this case, you have to set it in Windows path format (with backslashes, e.g. c:\my\custom\home), Git Bash will load it and convert it to its format.

If you want to change the home directory for all users on your machine, set it as a system environment variable, where you can use for example %USERNAME% variable so every user will have his own home directory, for example:

HOME=c:\custom\home\%USERNAME%

If you want to change the home directory just for yourself, set it as a user environment variable, so other users won't be affected. In this case, you can simply hard-code the whole path:

HOME=c:\my\custom\home


Related Topics



Leave a reply



Submit