Appending crontab using ssh and sudo without root credentials


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Appending crontab using ssh and sudo without root credentials
# 1  
Old 04-21-2017
Appending crontab using ssh and sudo without root credentials

Hi,

i have two servers say server A and server B. i have a sudo user say user1 with full privilges on server A and B. i am trying to append the crontab entry of root from server A of server B with the following command. But its appending on A. i need to append it on server B.

please find the Command below which i am running on server A which should login to server B and append crontab entry of B. instead its appending on A only.

Code:
/usr/bin/sshpass -p 'password' /usr/bin/ssh -o StrictHostKeyChecking=no -l user1 10.10.10.10 -t 'echo password' | sudo -S  bash -c 'echo "30 10 * * * sh test.sh" >> /var/spool/cron/root'

# 2  
Old 04-21-2017
Depending on the OS, wouldn't it be easier to scp a file to /etc/cron.d?

If you need to do it this way, try putting backticks (the one to the left of the number 1) around the remote command

Code:
/usr/bin/sshpass -p 'password' /usr/bin/ssh -o StrictHostKeyChecking=no -l user1 10.10.10.10 -t `'echo password' | sudo -S  bash -c 'echo "30 10 * * * sh test.sh" >> /var/spool/cron/root'`

# 3  
Old 04-21-2017
sshpass is extremely insecure, because the password is passed as a parameter. This gives an opportunity for it to be intercepted.

This is the reason for plain ssh's "annoying" limitation of only accepting passwords from a terminal, and why you had to install a third party utility to do this.

sudo has the same limitation - it will not accept a password from 'echo password'. su also has the same limitation, in fact, any sane authentication system will have the same limitation. Password authentication means typed-in-realtime-by-a-human authentication and no substitutions for human are acceptable.

I suggest using ssh keys for noninteractive authentication for ssh, and also suggest configuring sudo for passwordless operation so you don't have to kludge a password into it.

Last edited by Corona688; 04-21-2017 at 12:58 PM..
# 4  
Old 04-21-2017
Hi Padow1

when i use backticks i am getting the below error.

Code:
-bash: echo password: command not found

Also its appending on server A not B.

Kindly help

Last edited by rbatte1; 04-24-2017 at 01:41 PM..
# 5  
Old 04-21-2017
Don't do that. Backticks don't make sense there. But that command is not going to work, period -- sudo does not work that way.

Quote:
sudo has the same limitation - it will not accept a password from 'echo password'. su also has the same limitation, in fact, any sane authentication system will have the same limitation.
I suggest using ssh keys for noninteractive authentication for ssh, and also suggest configuring sudo for passwordless operation so you don't have to kludge a password into it.

Once you do both of these, you will no longer need a third-party hacking utility to accomplish basic things. It's always easier when you use basic features as intended.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to check via SSH and credentials if file on remote server exists?

Hi there, I am sorry to ask that kind of beginner thing, but all the code I found online didnt work for me. All I want to do is: Check via SSH if a File exists on my webserver. The SSH login has to be with username and password. So I would be very thankful if somebody could write the line.... (8 Replies)
Discussion started by: Jens885544
8 Replies

2. UNIX for Beginners Questions & Answers

Sudo to root, but keep my own aliases?

I have a coworker that has set up some funky aliases in /etc/bash.alias, and he insists on leaving them that way. For example he aliased "ll" to "ls -lahtr", which really bugs me. Anyway, I was wondering if there were a way for me to sudo to root without reading /etc/bash.alias, or maybe have... (6 Replies)
Discussion started by: paqman
6 Replies

3. Red Hat

Sudo to user other than root but do not allow sudo to root

I have a set of RHEL 5 boxes running our ERP software on Oracle databases. I need to allow my DBA's to su to oracle and one other account (banner) without knowing the oracle or banner password. But I need to prevent them from su'ing to any other user especially root. I only want them to be able to... (1 Reply)
Discussion started by: westmoreland
1 Replies

4. SuSE

Auditors want more security with root to root access via ssh keys

I access over 100 SUSE SLES servers as root from my admin server, via ssh sessions using ssh keys, so I don't have to enter a password. My SUSE Admin server is setup in the following manner: 1) Remote root access is turned off in the sshd_config file. 2) I am the only user of this admin... (6 Replies)
Discussion started by: dvbell
6 Replies

5. UNIX for Dummies Questions & Answers

sudo on becoming root

Anyone able to explain why if i run "sudo -i" or "sudo -s" i am able to get into root by just keying my own password? How to avoid this from happening coz i need all the users to use su - only. (2 Replies)
Discussion started by: timmywong
2 Replies

6. UNIX for Dummies Questions & Answers

Sudo to delegate permission from non-root user to another non-root user

I've been through many threads before i decide to create a separate thread. I can't really find the solution to my (simple) problem. Here's what I'm trying to achieve: As "canar" user I want to run a command, let's say "/opt/ocaml/bin/ocaml" as "duck" user. The only to achieve this is to... (1 Reply)
Discussion started by: canar
1 Replies

7. Shell Programming and Scripting

ssh foo.com sudo command - Prompts for sudo password as visible text. Help?

I am writing a BASH script to update a webserver and then restart Apache. It looks basically like this: #!/bin/bash rsync /path/on/local/machine/ foo.com:path/on/remote/machine/ ssh foo.com sudo /etc/init.d/apache2 reloadrsync and ssh don't prompt for a password, because I have DSA encryption... (9 Replies)
Discussion started by: fluoborate
9 Replies

8. Shell Programming and Scripting

Cron job initiating ssh AND sudo (from user, not root)

I've been bashing my head on the desk for 2 days trying to get this to work, but I've had no luck. I'll try to be as clear as possible in my explanation without dragging out the details. I'm trying to set up a cron job for user "john" which runs a script. This script initiates an ssh connection to... (5 Replies)
Discussion started by: eh3civic
5 Replies

9. AIX

make a mksysb without root credentials

dears, good day. i need to be able to take a mksysb for a machine running aix 6.1.5 without the root credentials and also without using sudo any advice ? (2 Replies)
Discussion started by: islam.said
2 Replies

10. UNIX for Dummies Questions & Answers

Possible to give non root user sudo to "crontab -l"

Does anyone know if this is possible? I want to give some users access to root's crontab but only with a read privilege. Is this possible to do or can only root or people with full root sudo view root's cron? (4 Replies)
Discussion started by: LordJezoX
4 Replies
Login or Register to Ask a Question