assign user with root privilege and permisssion to access system files
Hi all,
I want to write a cron job script to backup up the system files of the remote machine through ssh. As the remote machine does not allow ssh root login for security reason, how to create an ordinary account that has root privilege and permission so that this account can access and read those files that required root privilege and permission |
Why dont you log in normally, and then "su" and then issule the crontabs? This way the crontabs are running from the root user but I've given you below how to make a new user with root
create a new user type the command: "adduser", if that doesn't work, useradd -m <username> set the password: passwd <user> set the group: gpasswd -a <username> root and the user should have root access, allowing it to read and write root files. - This does set a secuirty risk to the operating system. |
Hi Master Fox,
I don't get what is mean about login normally and then "su" and then issue crontabs. The script will run in the local machine and will connect to remote mahine through ssh. The sample script will be as follows: cd /home/backup ssh user@remotemachine "cd / ; tar cf - etc"|tar xvf - ( The user need root privilege and permission to access the remote machine /etc directory ) |
well how I mean, "su" is a super user command, it allows you to log in as root from a normal user account.
[paw-fox@ ~]$ su Password: (your root password) [root@ /]# Whatever I do when logged into SU will run as root, so if I deicded to do crontab it would be running from root. if you used your script: "crontab -e 30 18 * * * ssh user@remotemachine "cd / ; tar cf - etc"|tar xvf -" (I know it woudn't work) it would run the process given as root allowing full acess to the system If you can already login as a normal user (I assume you can) use the SU command |
I run as you told as follows:
I logged in su and run as root and run the script, testScript root> ./testScript It gives the following error: crontab: usage error: no arguments permitted after this option usage: crontab [-u user] file crontab [-u user] [ -e | -l | -r ] (default operation is replace, per 1003.2) -e (edit user's crontab) -l (list user's crontab) -r (delete user's crontab) -i (prompt before deleting user's crontab) -s (selinux context) *************************************************************** Details of testScript script as follows: #!/bin/sh source ~/.keychain/localmachine-sh cd /home/backup crontab -e 50 11 * * * ssh user@remotemachine "cd /; tar cf - etc"|tar xvf - ***************************************************************** Any idea what went wrong |
I would have to pass, my scripting abities are quite low when it comes to bash scripting, I guess another way would be do all your jobs would be placing it in a file
--- cd /home/backup tar cf - etc"|tar xvf - --- then use crontab to run that script, so "crontab -e 50 11 * * * bash script.sh" but otherwise I can't help you any more. |
It works now. Thanks
|
All times are GMT -5. The time now is 10:42 PM. |