How to configure jenkins to give password while executing shell script in remote server - linux

I have a shell script to do deployment on a remote server. But I didn't have full root privileges for that server and it asks password for every steps (4-5 times while executing the script).
Now, I want to run the shell script using Jenkins. How to configure jenkins to give the password while executing the shell script in remote server.
Thanks in advance

Add myuser ALL=(ALL) NOPASSWD: ALL in /etc/sudoers.
Note: Replace myuser with your actual username.

Related

Cannot switch to jenkins user on aws ec2 linux?

When I ssh into an aws ec2 Linux instance, I am ec2-user. The instance is a Jenkins master. When I try su - jenkins and entered the correct password, the system says Last login: .... which looks like the switching succeeded. But whoami says I'm still ec2-user.
What am I missing? Thanks!
jenkins is a service account, it doesn't have a shell by design. It is generally accepted that service accounts shouldn't be able to log in interactively.
if you really want to login as Jenkins, you can do so with: sudo su -s /bin/bash jenkins

Automatically apply puppet catalog upon login to client node

I tried to execute shell script automatically when a user logins to a Puppet client node. I need to trigger puppet agent --test on a puppet client when a user logins to it.
I need to execute "puppet agent -t" command automatically when any user login to puppet client machine
That is going to be problematic, as puppet needs to run as root.
You can add
sudo puppet agent -t
to your /etc/profile , and also add
ALL ALL=(ALL) NOPASSWD: puppet
to your /etc/sudoers file.
But this is NOT something I would recommend.

Why does jenkins need sudo password when ssh account doesn't?

My linux user account has the rights to run a particular sudo command without a password prompt. I am trying to implements jenkins to run this command. It is set up to ssh as my user account on the box with the Publish Over SSH plugin.
When I am in the box $USER shows the correct user, but when I try to run "sudo {command}" (which runs without password when I am using that box normally with my user) it requires password. What is causing this behavior?
Because it is configured to do so. There is file /etc/sudoers specifying these rules and there is respective manual page describing how does this file and the roles work. It is probably a good start to read.

Automate Linux server login with 2 users using terminal in Ubuntu 14.04

I need to authenticate with two users on a Linux server using the following users:
user1
root
I could automate with user1 using a tool named - sshpass. Post which the terminal just looses the communication with the local machine and hence ignores the commands which comes after. My shell script is as follows:
sshpass -p my_password ssh user1#my_domain_name
spawn su
root_password
How to make the above script to automate the input of root password as well. ?
The tools like Tera_Term and MTputty works great in windows but what in Ubuntu (14.04) ?

Is it possible to allow jenkins to access the files that only root or some specific programs have access to?

What I'm basically trying to do is allow jenkins access my android-sdk-linux folder and all the sub-directories. My boss does not want to change permissions on the folder himself. I am supposed to do it during the build process. I have seen some examples that run some commands in the execute shell during the build process. Is there some commands that can I can run in that execute shell so that jenkins can have read write and execute authority on my android-sdk-linux folder?
As bcolfer said, you should be able to just run your shell commands with "sudo" in front of it. You will want to be sure that the user that started the Jenkins slave is a sudoer.
As root, run "visudo", this will open the /etc/sudoers file. At the bottom add a line similar to this if it is not a current sudoer:
jenkins ALL=(ALL) NOPASSWD: ALL
"Jenkins" being the user that started the slave.
OR
You could try adding the user to the group that owns that directory. IF you run "ls -l" you should be able to see the permissions and then the user, and the group that owns the directory. Once you know the group, as root run:
usermod -a -G group Jenkins
"Jenkins" being the user that started the slave, and "group" being the actual group name.
One possibility is to use sudo to run commands that specifically target those files. There are a bunch of ways to manage the sudo privileges limit and log what actions happen on those files.

Resources