How can a GitLab ssh url show a non-default user? - gitlab

I have a GitLab installation, but it is installed under a different user to the default 'git'.
On project pages, users are instructed to use the following URL for ssh:
git#host:user/project.git
How do I change this to show the new username?

Try and modify/uncomment the lines regarding ssh use in gitlab.yml
# Uncomment and customize if you can't use the default user to run GitLab (default: 'git')
# user: git
The initializer is supposed to use that setting when computing the ssh url for repos.
See "config/initializers/1_settings.rb#L12-L18"
def build_gitlab_shell_ssh_path_prefix
if gitlab_shell.ssh_port != 22
"ssh://#{gitlab_shell.ssh_user}##{gitlab_shell.ssh_host}:#{gitlab_shell.ssh_port}/"
else
"#{gitlab_shell.ssh_user}##{gitlab_shell.ssh_host}:"
end
end

Related

Why some gitlab project clone with SSH do not have SSH schema?

when I watch a tutorial:
when clone a project with SSH, it shows git#xxx like below:
but when I use my Gitlab in practice:
there have schema ssh://, what's the difference?
ssh://git#gitlab.demo.com:222/xxx
That depend on how the custom SSH URL was set for your GitLab instance:
gitlab-ctl show-config | gitlab_ssh_host
The default one uses the default SSH URL scheme, using '/' only.
But you can set it to a SCP-style URL, without ssh://, and using a ':' between domain and URL path.
To change it:
Edit /etc/gitlab/gitlab.rb
Search for gitlab_rails['gitlab_ssh_host'] = 'your.hostname.here'
Update the hostname value and run a gitlab-ctl reconfigure afterwards.

GitLab username in URL for clone

How do I configure the GitLab URL username?
Why is the username in the Git clone URL always git#url?
Even if we create own user it still says git.
I have created my ssh key and added to the GitLab, but still it says git#url.
It does say git because it is the account under which GitLab server has been installed.
It is defined in the gitlab.yml config file.
# Uncomment and customize if you can't use the default user to run GitLab
(default: 'git')
# user: git
You will always contact GitLab ssh with that user 'git': that SSH session will use your public SSH key, and that will allow the GitLab server to authenticate you.
Since it is an SSH URL, you need to open a (non-interactive) ssh (secure shell) session always with the account git, which will have your public SSH key registered.

Gitlab 'fatal: repository '...' not found' - unable to push to a newly created project

Can anyone spot what I could possibly be doing wrong? You can browser zoom in to see image details.
This is a fresh account, new project, owner of group and I am simply unable to push (HTTPS) following instructions provided.
When adding the remote URL to the initial configuration, instead of using the URL that Gitlab gives you, try adding the following URL instead and replace the details below as mentioned, to reflect your info & your project info:
REMOTE URL FORMAT:
https://YOUR_USER_NAME:PASSWORD#gitlab.com/YOUR_USER_NAME/YOUR_PROJECT_NAME.git/
REPLACEMENTS IN THE ABOVE URL:
YOUR_USER_NAME - Replace this with your gitlab username
PASSWORD - Replace this with your gitlab password
YOUR_PROJECT_NAME - Replace this with your gitlab project name (whatever is generated for you)
I create a small site to fix really quick this issue. gitlab fix remote
While Adding Your URL make sure you add your username like this
https://username#gitlab.com/path_of_repository.git
and also .git at the end is not to be missed
try to /profile/keys and add new key of server in GitLab
In your GitLab got to: /help/ssh/README
SSH keys
An SSH key allows you to establish a secure connection between your computer and GitLab.
In my case for HTTPS-URL, it was not working
So I tried using it with SSH
First open command prompt in administrator mode then enter the following command to generate SSH key:
ssh-keygen -t rsa -b 4096 -C “<my key name>”
Then go to the location where this key is saved 'In my case (C:\Users\your_username\.ssh)' and open id_rsa.pub and copy its content.
Then go to GitLab create a new SSH key and add this copied content to your SSH key.
After that try cloning using SSH-URL

Gitlab: how to change OS (ssh) user and group for Gitlab installation?

What is the correct way to change default OS (ssh) user and group git/git, which are used during Gitlab installation, to something else (e. g. gitlab/gitlab) ?
After that manipulation a repo address should looks like gitlab#host.com:repo.git, not default git#host.com:repo.git.
It's necessary because default 'git' user is used for another purpose on my server and cannot be used for Gitlab installation.
My OS: Ubuntu Server 12.04 x64
Gitlab installation guide: https://github.com/gitlabhq/gitlabhq/blob/master/doc/install/installation.md
Thanks.
There are a few steps to do:
Create a new user (or use another created on) for GitLab
Change user of GitLab in gitlab.yml to the new user
Change user of gitlab-shell in config.yml to new user
Grant the new user access to gitlab-shell and GitLab directory
Apply all permission instructions from the installation docs for the new user

How to input password to git pull command?

I have written scripts for Windows and Linux to essentially set up a new users workspace with all the git repositories from our server.
I would like the user to enter the password for our server once, store it in a local variable, pass that variable to each git pull command, then erase the password variable and exit.
How can I input the password when the git pull command requests it? Both for Windows batch file and a Linux shell script.
Here is code from the Linux script:
#!/bin/bash
echo "Enter password: "
read pswd
clear #No screen peaking
#This is repeated for each repo
location=folderName
mkdir $location
cd $location
git init
git remote add origin git#<server>:$location.git
git pull origin master
#Above prompts for password & is where I want to automatically input $pswd
I've tried various things recommended on SO and elsewhere, such as piping, reading from .txt file, etc. I would prefer to not need anything more than plain old windows cmd and Linux terminal commands. And as this script is just for set up purposes, I do not need to securely store the password permanently with something like ssh agent.
I'm running Windows 7 and Ubuntu 12.10, but this script is meant for setting up new users, so it should ideally work on most distributions.
Synopsis:
git pull "https://<username>:<password>#github.com/<github_account>/<repository_name>.git" <branch_name>
Example:
git pull "https://admin:12345#github.com/Jet/myProject.git" master
Note: This works for me on a bash script
I would really recommend to not try and manage that password step, and delegate that (both on Linux and Windows) to git credential helper.
See:
"Git http - securely remember credentials"
"How to use git with gnome-keyring integration"
The user will enter the password only once per session.
Read the remote url from git and then insert the ID and password (PW) to the url might work.
For example try the following:
cd ${REPOSITORY_DIR}
origin=$(git remote get-url origin)
origin_with_pass=${origin/"//"/"//${USER_ID}:${USER_PW}#"}
git pull ${origin_with_pass} master

Resources