Hi @Ayman, @rahul456, and everyone,
Once again, being new to Jenkins I am again stuck.
On this particular task I am ending up with a
permission denied error.
Steps that I have taken so far:
1 => Login to UI
2 => update plugins
3 => install plugin `SSH Build Wrappers`
4 => Jenkins --> Manage Jenkins --> Credentials --> add credentials
- add `banner` + `natasha` + passwords
5 => Jenkins --> Manage Jenkins --> configure system --> go to section ( ssh remote hosts) -- add hostnames + port 22
6 => add users to sudoer file
ssh [email protected] BigGr33n
banner ALL=(ALL) NOPASSWD: ALL
ssh [email protected] [email protected]
natasha ALL=(ALL) NOPASSWD: ALL
7 => Create a Jenkins jobs named `copy-logs`
=> click (in UI) => `build periodically`
*/11 * * * *
8 => execute remote shell w/ssh
sudo mkdir /tmp/logs
sudo cp /var/log/httpd/access_log /tmp/logs
sudo cp /var/log/httpd/error_log /tmp/logs
sudo scp /tmp/logs/access_log -o StrictHostKeyChecking=no [email protected]:/usr/src/sysops
sudo scp /tmp/logs/httpd/error_log -o StrictHostKeyChecking=no [email protected]:/usr/src/sysops
sudo rm -rf /tmp/logs
Permission denied publickey
Any help would be awesome! Thanks in advance to anyone who can help:-)
PS. I also tried:
echo "BigGr33n" | sudo mkdir /tmp/logs
echo "BigGr33n" | sudo cp /var/log/httpd/access_log /tmp/logs
echo "BigGr33n" | sudo cp /var/log/httpd/error_log /tmp/logs
echo "BigGr33n" | sudo chown -R jenkins:jenkins /tmp/logs
echo "BigGr33n" | sudo chmod -R 777 /tmp/logs
scp -r -o StrictHostKeyChecking=no /tmp/logs/access_log/* [email protected]:/usr/src/sysops
echo "BigGr33n" | sudo rm -rf /tmp/logs
…which also failed to execute the script & copy the files
If you are supplying sudo password via shell command, then you need to use
sudo -S option. For example, your command will look like this:
echo "BigGr33n" | sudo -S mkdir /tmp/logs
But I’m not sure if the ‘public key’ error you mentioned is because of this. But certainly, your
sudo will not work in its current form.
Thanks @phantomsg! I will take note of that.
Do you know why the
-S tag is needed in this case?
sudo command to read password from
stdin. See the Linux Man entry for sudo command
Thank you @phantomsg for explaining that to me (and thanks for the link)! I get it now.
Hey @juliettet were you able to finish this task? DId you find out root cause for public_key error? I am stuck on that. Trying different ways but dont help.
It’s been a while…I did finish the task. Can you give me a run down on which steps you have taken so far so that I can compare what you have with my notes to see what you may be missing?
Thanks for replying back @juliettet. I DM you please check.
I have just messaged you:-)
@oqtay.tasinov Hi, Can you guys help me with where i went wrong with, as i see output is successful but the task failed.
- Installed Plugin SSH Build wrappers
- Added credentials
- Created Job copy-logs
- added build periodically according to question
and execute below
echo “BigGr33n”| sudo -S mkdir -p /tmp/logs1
echo “BigGr33n” | sudo -S cp /var/log/httpd/access_log /tmp/logs1
echo “BigGr33n” | sudo -S cp /var/log/httpd/error_log /tmp/logs1
echo “BigGr33n” | sudo -S chmod 777 /tmp/logs1
echo “BigGr33n” | sudo -S chown -R root:root /tmp/logs1
echo “BigGr33n” | sudo -S yum install sshpass -y
sshpass -p “[email protected]” scp -o ‘StrictHostKeyChecking=no’ /tmp/logs1/access_log [email protected]:/usr/src/data
sshpass -p “[email protected]” scp -o ‘StrictHostKeyChecking=no’ /tmp/logs1/error_log [email protected]:/usr/src/data
[sudo] password for banner: Loaded plugins: fastestmirror, ovl
Loading mirror speeds from cached hostfile
[SSH] exit-status: 0
The task is failed , don’t think i missed anything.
hi @sudheer, seems like you have completed the task.
@rahul456 says that you have completed the task. Congratulations and great work!!
@rahul456 Yes, i did complete the task.