Setting up sshkey for git bash on windows 10 VM - bitbucket

OS: Ubuntu with windows 10 VM
Goal: Setup git bash on the Windows 10 VM with an ssh key to use with private Bitbucket.
Overview:
Generating an SSH key into a non-default location to work with git bash did not work. An attempted solution was to create default location and move the key to that location to test. I do not know enough about how the default location is generated, or how git bash searches for the sshkey to compare with bitbucket. I suspect network drives/IT may be impacting the issue but do not know the correct questions to ask. The steps and details are below. Yes the ssh key was added to bitbucket account.
When generating the ssh key the suggestion location is /home/username/.ssh... I am not sure where this suggested path comes from. I have set several computers up with git bash/ssh keys and this suggested path varies. How does this suggested path get set? and How is the ssh key Search Path set?
ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/plane/.ssh/id_rsa): /c/Users/username/.ssh/id_rsa
~ pwd = c/Users/username
/ does exist, but home does not exist
$ ls -l /
total 3076
drwxr-xr-x 1 username 1061577 0 Feb 3 15:57 bin/
drwxr-xr-x 1 username 1061577 0 Feb 3 15:57 cmd/
drwxr-xr-x 1 username 1061577 0 Feb 3 15:57 dev/
drwxr-xr-x 1 username 1061577 0 Feb 3 15:57 etc/
-rwxr-xr-x 1 username 1061577 152112 Jan 13 20:31 git-bash.exe*
-rwxr-xr-x 1 username 1061577 151600 Jan 13 20:31 git-cmd.exe*
-rw-r--r-- 1 username 1061577 18765 Dec 10 18:25 LICENSE.txt
drwxr-xr-x 1 username 1061577 0 Feb 3 15:56 mingw64/
dr-xr-xr-x 13 username 1061577 0 Feb 3 17:57 proc/
-rw-r--r-- 1 username 1061577 160771 Jan 13 21:08 ReleaseNotes.html
drwxr-xr-x 1 username 1061577 0 Feb 3 17:02 tmp/
-rw-r--r-- 1 username 1061577 1161914 Feb 3 15:57 unins000.dat
-rwxr-xr-x 1 username 1061577 1299888 Feb 3 15:51 unins000.exe*
-rw-r--r-- 1 username 1061577 22795 Feb 3 15:57 unins000.msg
drwxr-xr-x 1 username 1061577 0 Feb 3 15:57 usr/
Permissions denied
mkdir -p /home/username
mkdir: cannot create directory ‘/home’: Permission denied
Git Clone:
$ git clone ssh://git#git.example.com/project.git
Cloning into 'project'...
Could not create directory '/home/username/.ssh'.
The authenticity of host 'example' can't be established.
RSA key fingerprint is SHA256.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Failed to add the host to the list of known hosts (/home/username/.ssh/known_hosts).
example: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Edit:
I have attempted the following as well.
In an effort to indicate where .ssh actually is, and where I want it to be.
/c/Users/plane/.ssh
git config --global core.sshCommand "ssh -i ~/.ssh/id_rsa.pub"
1) Could not create '/home/plane/.ssh'
2) Failed to add the host to the list of known hosts (/home/plane/.ssh/known_hosts).
3) Load key "/c/Users/plane/.ssh/id_rsa.pub": invalid format
git clone ssh://git#git.project
Cloning into 'project'...
Could not create directory '/home/plane/.ssh'.
The authenticity of host can't be established.
RSA key fingerprint is SHA256:.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Failed to add the host to the list of known hosts (/home/plane/.ssh/known_hosts).
Load key "/c/Users/plane/.ssh/id_rsa.pub": invalid format
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Thank you,

You should use:
a regular CMD (in your Windows 10 VM) with a simplified path
set PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\
set GH=C:\path\to\git
set PATH=%GH%\bin;%GH%\usr\bin;%GH%\mingw64\bin;%PATH%
a key generated in the default %USERPROFILE%.ssh folder
ssh-keygen -P "" -t rsa -m PEM
register the id_rsa.pub content to your BitBucket profile
The known_hosts is still referenced at the default location /home/username/.ssh.
How do I change this default location?
This is managed by the $HOME/%HOME% environment variable.
SSH will look for known_hosts in $HOME/.ssh

Related

Jailkit User Cannot Execute Nextcloud OCC Commands

I have a fresh install of nextcloud 22.2.0, that I installed according to [these instructions:]1
After NC installation, I hae ZERO errors in my NC log. However, in the Overview section I have some basic wearnings that I know are "false positives" forllowing a new installation. There I want to run the NC occ in order to repair things:
./occ integrity:check-core
However, I get these errors:
Your data directory is invalid
Ensure there is a file called ".ocdata" in the root of the data directory.
Cannot create "data" directory
This can usually be fixed by giving the webserver write access to the root directory. See https://docs.nextcloud.com/server/22/go.php?to=admin-dir_permissions
Setting locale to en_US.UTF-8/fr_FR.UTF-8/es_ES.UTF-8/de_DE.UTF-8/ru_RU.UTF-8/pt_BR.UTF-8/it_IT.UTF-8/ja_JP.UTF-8/zh_CN.UTF-8 failed
Please install one of these locales on your system and restart your webserver.
An unhandled exception has been thrown:
Exception: Environment not properly prepared. in /web/lib/private/Console/Application.php:162
Stack trace:
#0 /web/console.php(98): OC\Console\Application->loadCommands(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#1 /web/occ(11): require_once('/web/console.ph...')
#2 {main}
I was able to resolve this error:
Setting locale to en_US.UTF-8/fr_FR.UTF-8/es_ES.UTF-8/de_DE.UTF-8/ru_RU.UTF-8/pt_BR.UTF-8/it_IT.UTF-8/ja_JP.UTF-8/zh_CN.UTF-8 failed
Please install one of these locales on your system and restart your webserver.
By using:
chattr -i /var/www/clients/client1/web19/
jk_cp -j /var/www/clients/client1/web19/ /usr/lib/locale
chattr +i /var/www/clients/client1/web19/
Can anyone tell me how to resolve the two remaining errors so that the NC occ will work correctly?
thanks
Also the user's permissions are correct:
# ls -la /var/www/clients/client1/web19
total 60
drwxr-xr-x 15 root root 4096 Nov 12 15:12 .
drwxr-xr-x 9 root root 4096 Nov 12 14:50 ..
lrwxrwxrwx 1 root root 7 Nov 12 15:09 bin -> usr/bin
drwxr-xr-x 2 web19 client1 4096 Nov 12 14:50 cgi-bin
drwxr-xr-x 2 root root 4096 Nov 12 17:36 dev
drwxr-xr-x 8 root root 4096 Nov 12 15:12 etc
drwxr-xr-x 4 root root 4096 Nov 12 15:12 home
lrwxrwxrwx 1 root root 7 Nov 12 15:09 lib -> usr/lib
lrwxrwxrwx 1 root root 9 Nov 12 15:09 lib64 -> usr/lib64
drwxr-xr-x 2 root root 4096 Nov 12 19:58 log
drwx--x--- 2 web19 client1 4096 Nov 12 20:05 private
drwx------ 2 web19 client1 4096 Nov 12 15:09 .ssh
drwxr-xr-x 2 root root 4096 Nov 12 14:55 ssl
drwxrwx--- 2 web19 client1 4096 Nov 12 20:09 tmp
drwxr-xr-x 8 root root 4096 Nov 12 15:09 usr
drwxr-xr-x 4 root root 4096 Nov 12 15:12 var
drwx--x--x 14 web19 client1 4096 Nov 12 20:09 web
drwx--x--- 2 web19 client1 4096 Nov 12 14:50 webdav
I had the same problem as you and, curiously, I use the same user/client for the same service.
I've resolved in the following way (in addition to yours solution about "locale").
Go into the jail root (/var/www/clients/client1/web19). Here create the directories to contain PHP stuff:
mkdir -p etc/php/7.4/cli/conf.d
Copy the system-wide php.ini for cli into jail:
cp -a /etc/php/7.4/cli/php.ini etc/php/7.4/cli/php.ini
"Hardly" link every file *.so present in system-wide conf into the jail. For example:
ln /etc/php/7.4/mods-available/apcu.ini 20-apcu.ini
If you has the cache problems too (as me), you can add a definition before run occ.
I'm using the following command:
runuser -l web19 -c "cd /web; php --define apc.enable_cli=1 ./occ"
...and all seems to works fine! :-)

Mounted Docker volume has different ownership when using Travis

This question relates to this repository with the most relevant Travis job here.
The repository is for static site built from Jupyter notebooks. The notebooks are converted using build/build.py which, for each post, builds a Docker image, starts a corresponding container with the post notebook directory mounted, and uses nbconvert to convert the notebook to Markdown. One step of nbconvert's conversion involves creating a supporting file directory. This fails on Travis due to a permission issue.
In attempting to debug this problem, I found that the ownership and permissions of the repo are the same on my local machine and Travis (with my username switched for travis) before running Docker. Despite this, inside the mounted volume of the Docker container, the ownerships are different:
Local:
drwxrwxr-x 3 jovyan 1000 4096 Dec 10 19:56 .
drwsrwsr-x 1 jovyan users 4096 Dec 3 21:51 ..
-rw-rw-r-- 1 jovyan 1000 105 Dec 7 09:57 Dockerfile
drwxr-xr-x 2 jovyan 1000 4096 Dec 10 12:09 .ipynb_checkpoints
-rw-r--r-- 1 jovyan 1000 154229 Dec 10 12:28 post.ipynb
Travis:
drwxrwxr-x 2 2000 2000 4096 Dec 10 19:58 .
drwsrwsr-x 1 jovyan users 4096 Nov 8 16:37 ..
-rw-rw-r-- 1 2000 2000 101 Dec 10 19:58 Dockerfile
-rw-rw-r-- 1 2000 2000 35271 Dec 10 19:58 post.ipynb
Both my local machine and Travis are running Ubuntu 20.04, have the same version of Docker, and all other tools come from Conda so should behave the same. I am struggling to understand where this difference in ownership is coming from.
Try running the docker again with this command, so the uid outside the container is propagated inside:
docker run -u `id -u`
alternative, as pointed by #anemyte:
docker run -u $(id -u)
This should involve the creation of the new files inside the docker to be owned by "jovyan".
If you are able to guess that mounting points will exist, you could also pre-create them so the ownership of the files inside is also correct:
docker run -v /path/on/host:/path/in/container ...
If you set the permissions of your local path (/path/on/host) as 777, that will also be propagated to the mounting point: no permission error will be thrown regardless of the user that docker uses to create those files.
After that, you'll be free to restore permissions, if needed.

How can Docker container write to a mounted directory with permissions granted through group membership?

Versions
Host OS: Debian 4.9.110
Docker Version: 18.06.1-ce
Scenario
I have a directory where multiple users (user-a and user-b) have read/write access through a common group membership (shared), set up via chown:
/media/disk-a/shared/$ ls -la
drwxrwsr-x 4 user-a shared 4096 Oct 7 22:21 .
drwxrwxr-x 7 root root 4096 Oct 1 19:58 ..
drwxrwsr-x 5 user-a shared 4096 Oct 7 22:10 folder-a
drwxrwsr-x 3 user-a shared 4096 Nov 10 22:10 folder-b
UIDs & GIDs are as following:
uid=1000(user-a) gid=1000(user-a) groups=1000(user-a),1003(shared)
uid=1002(user-b) gid=1002(user-b) groups=1002(user-b),1003(shared)
Relevant /etc/group looks like this:
shared:x:1003:user-a,user-b
When suing into both users, files can be created as expected within the shared directory.
The shared directory is attached to a Docker container via mount binds to /shared/. The Docker container runs as user-b (using the --user "1002:1002" parameter)
$ ps aux | grep user-b
user-b 1347 0.2 1.2 1579548 45740 ? Ssl 17:47 0:02 entrypoint.sh
id from within the container prints the following, to me okay-looking result:
I have no name!#7a5d2cc27491:/$ id
uid=1002 gid=1002
Also ls -la mirrors its host system equivalent perfectly:
I have no name!#7a5d2cc27491:/shared ls -la
total 16
drwxrwsr-x 4 1000 1003 4096 Oct 7 20:21 .
drwxr-xr-x 1 root root 4096 Oct 8 07:58 ..
drwxrwsr-x 5 1000 1003 4096 Oct 7 20:10 folder-a
drwxrwsr-x 3 1000 1003 4096 Nov 10 20:10 folder-b
Problem
From within the container, I cannot write anything to the shared directory. For touch test I get the following i.e.:
I have no name!#7a5d2cc27491:/shared$ touch test
touch: cannot touch 'test': Permission denied
I can write to a directory which is directly owned by user-b (user & group) and mounted to the container... Simply the group membership seems somehow not to be respected at all.
I have looked into things like user namespace remapping and things, but these seemed to be solutions for something not applying here. What do I miss?
Your container user has gid=1002, but is not member of group shared with gid=1003.
Additionally to --user "1002:1002" you need --group-add 1003.
Than the container user is allowed to access the shared folder with gid=1003.
id should show:
I have no name!#7a5d2cc27491:/$ id
uid=1002 gid=1002 groups=1003

Docker does not find executable

I have an executable written in Golang, it starts and runs fine when started from the Linux-prompt. As you can see, the executable needs an XML file when started. But when started inside a Docker environment, I get error message:
standard_init_linux.go:190: exec user process caused "no such file or directory"
Let me tell you what I tried. First, this is my Dockerfile:
FROM alpine:latest
MAINTAINER Bert Verhees "xxxxx"
ADD archibold_ucum_service /archibold_ucum_service
ADD data/ucum-essence.xml /data/ucum-essence.xml
ENTRYPOINT ["/archibold_ucum_service", "-ucumfile=/data/ucum-essence.xml"]
I build it in this way:
docker build -t=ucum_micro_service .
Then I start it in this way
docker run --name=ucum_micro_service -i -t ucum_micro_service /bin/sh
When I do this, I get the error-message, as displayed above. Then I tried commenting out the ENTRYPOINT line, and then it builds OKAY and it starts the linux prompt, so I can query what is inside.
The executable is in it, and the data-file also. And the executable also has the right attributes (it is executable inside the docker-container)
Then I try to start the executable from the linux-prompt, inside the started container, and then I get again a message that the file is not found:
/ # ./archibold_ucum_service
/bin/sh: ./archibold_ucum_service: not found
For completeness, here is partly the directory-structure in the container:
/ # ls -l
total 17484
-rwxrwxr-x 1 root root 17845706 Aug 3 13:21 archibold_ucum_service
drwxr-xr-x 2 root root 4096 Jul 5 14:47 bin
drwxr-xr-x 2 root root 4096 Aug 3 14:29 data
drwxr-xr-x 5 root root 360 Aug 4 20:27 dev
drwxr-xr-x 15 root root 4096 Aug 4 20:27 etc
drwxr-xr-x 2 root root 4096 Jul 5 14:47 home
drwxr-xr-x 5 root root ........
.......
So, what can be the problem. I am trying to solve this for over a day now. Thanks for support.

Cannot delete folder in Ubuntu in Windows 10

I have a rails app in a folder in Ubuntu. I am using atom and git. I've always run git from the console, but last night I installed the hydrogen package on atom, so I can run git from atom. After this my app was a mess. I was trying to switch from one branch to another, but the files from one branch were transferred to the one that I had just switched to. I finally switched to master branch, which was supposed to have just the default files, but there were about 2000 files to commit. I tried to delete the folder but it doesn't work. Any suggestions about how to delete it, and some tips about using git on atom, when using Ubuntu?
$ ls -la
total 0 drwxrwxrwx 1 raluca raluca 4096 May 30 13:37
. drwxrwxrwx 1 raluca raluca 4096 May 30 14:34
.. drwxrwxrwx 1 raluca raluca 4096 May 30 13:27
app drwxrwxrwx 1 raluca raluca 4096 May 30 13:37
db drwxrwxrwx 1 raluca raluca 4096 May 29 19:53
public drwxrwxrwx 1 raluca raluca 4096 May 30 13:27
test drwxrwxrwx 1 raluca raluca 4096 May 29 19:53 vendor
I had the same problem (using Ubuntu on Windows). I created a file that was in my home directory and I could not delete it either with Linux (sudo rm filename) or with Windows (del filename). I got permission denied on both.
The solution was to:
First use chmod 777 ~ granting any user permission to edit directory.
Then use chown username filename, so that your current username can delete the file.
If you run rm filename you will still get the permission denied error at this point. Therefore, to let your previous commands take effect you will need to shut down your computer.
Restart your computer and check the home directory with bash ls, the file should be gone. It was for me. However, it will probably have moved to a different directory on your computer (i.e. in your Windows C drive "home directory").
So open cmd as admin and run dir "\filename*" /s (You will see file is still on computer but moved to C:\Users\username. Navigate to that folder using cmd and type dir. You will see the file there.
Finally, in cmd type del filename to delete the file (no permission error). Or if it is a folder you want to delete use rd foldername /s. Type dir and you will see the file will be permanently deleted from your computer.
Since the files aren't commited yet, try this out:
git clean -f -d

Resources