Jenkins User on Apt-Get Install Installation

时间:2022-01-10 16:50:33

转自:http://*.com/questions/6234016/jenkins-user-on-apt-get-install-installation

QUESTION:

I just installed Jenkins on my Ubuntu server via the debian installation steps (using apt-get install). I want my build to pull from a private git repository on GitHub. With that, I need to use SSH access to get to my repository.

Most of my search results have just said to login as the Jenkins user and generate an SSH key for my GitHub account, but installing through the debian package manager, I don't have a password for the Jenkins user.

So how do I generate an SSH key for my Jenkins server to use?

ANSWER:

I'll anticipate that from time to time you'll want to be able to log in as jenkins to do other tasks, and so I'll solve the more general problem. A strict answer to your question is included at the end.

Change jenkins' password without knowing it

From any account which has sudo permissions, you can reset jenkins' password to something of your choosing:

sudo passwd jenkins

You may be asked first for your own password, in order to use sudo. Then you will be prompted for the new password to set for jenkins, and finally a confirmation of that new password.

If your user with sudo rights is called joe, here's how a session might look:

joe $ sudo passwd jenkins
[sudo] password for joe: **you enter joe's passwd**
Enter new UNIX password: ** you enter new jenkins passwd**
Retype new UNIX password: ** you enter new jenkins passwd**
passwd: password updated successfully

Alternative: login as jenkins without his password

Alternatively, again using sudo from a suitable other account, you can login as jenkins without being asked for his password:

sudo su - jenkins

An aside: Avoiding password prompt confusion

Before issuing sudo passwd jenkins, we might first like to authenticate separately with sudo to avoid confusion around the question "whose password am I being asked for, now?".

sudo -v
sudo passwd jenkins

After a successful authentication by sudo, there is a window (e.g. 15 minutes) where we won't be prompted to authenticate again. (Note that you can immediately invalidate (kill) this session with sudo -k, if you want to experiment.)

The promised strict answer

sudo -u jenkins ssh-keygen

Then use cat to view the contents of the public key to be passed to github (but the path is only an example):

  sudo cat ~jenkins/.ssh/id_rsa.pub

The exact location and name of the public key file depends on what you entered to the prompts of ssh-keygen, above. I've used a shortcut to jenkins' home dir, ~jenkins.