Pages - Menu

標籤

AWS (1) bash (1) Boost (2) C (2) CMake (2) Concurrency_Programming (3) CPP (37) Database (2) DNS (1) Docker (4) Docker-Compose (1) ELK (1) emacs (4) gcp (1) gdrive (1) git (1) gitbash (2) gitlab (1) kvm (4) Linux (5) MT4 (4) MT5 (4) Multicast (2) MySQL (2) Nijatrader8 (1) OpenCV (1) Python (4) QT5 (1) R (1) rdp (3) screenshot (1) ssh (3) Tabnine (1) TCP (1) TensorFlow (1) Tools (12) Ubuntu_1904 (11) Ubuntu_20_04 (5) UDP (1) VS2010 (1) VS2015 (1) VS2019 (1) WebServer (1) Win10 (1) winmerge (1) WSL (1) xrdp (1)

搜尋此網誌

2020年2月16日星期日

Add ssh key to gitlab

On Linux

Create ssh key on linux machine

# generate ssh key
ssh-keygen -t rsa -b 4096 -C "user@gamil.com"
ls
--- newKey
--- newKey.pub

# list ssh agent
ssh-add -l
...
ssh-add -L
...

# add to ssh agent
ssh-add ~/.ssh/newKey


# list ssh agent
ssh-add -l
...
ssh-add -L
...


Add your public key to gitlab, and clone project through ssh.

On Window

Install git bash. Then we have to create your private key as shown on the above steps and you have to:

$ cat ~/.bashrc

# ssh-agent
SSH_ENV="$HOME/.ssh/environment"

function start_agent {
    echo "Initialising new SSH agent..."
    /usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
    echo succeeded
    chmod 600 "${SSH_ENV}"
    . "${SSH_ENV}" > /dev/null
    /usr/bin/ssh-add;
    ssh-add $HOME/.ssh/<user private key>
}

# Source SSH settings, if applicable

if [ -f "${SSH_ENV}" ]; then
    . "${SSH_ENV}" > /dev/null
    #ps ${SSH_AGENT_PID} doesn't work under cywgin
    ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
        start_agent;
    }
else
    start_agent;
fi

On Gitlab

You have to add public key to gitlab:


Clone project from gitlab through ssh method

 

 

沒有留言:

發佈留言