How to execute a script without password and root privileges - unix

i am trying to execute a script as a non root user.password is required here to execute the script. Am able to execute the script with password as a non root user.is there any possible way to execute the script without root privileges and also without entering the password.

If a script requires root privileges to run, there is no way to legally circumvent that and run the script without such privileges.

Related

Unix how to create files and directories with specific user

I'm trying to create files and directories and executing a script with a specific user instead of root user. How can I do that? I don't want to switch users from root user to another user; instead, I always want it to use a specific user, for example, wasadmin user.
Whenever I'm creating a new file or executing a script, this should be run as wasadmin user. Can you please help me with this?
It depends on how you create the file. As far as I know, it's not possible to do this when you use touch or echo, but depending on the way you create the file, there might be a possibility to add a user parameter.
In case this is not possible, you might use the chown command (change ownership), this command gives the possibility to modify the owner/group of an already created file (which obviously means that you can only do this after the file has already been created). I've been looking for an official chown reference, but I think that launching the command man chown can answer all questions you might have on this command.

Crontab won't run for user

I'm trying to run crontab as a user, but any of the scripts won't execute. How I can fix this? Consider that:
I tried with BOTH crontab -e and sudo crontab -u username -e;
Scripts are correctly written, since they are executed if I run them
with root crontab;
In cron.allow there are both root and user.
Crontab Permissions:
There are two files that control the permissions for crontab: /etc/cron.allow and /etc/cron.deny.
If there is a cron.allow file, then the user or users that need to use cron will need to be listed in the file. You can use cron.deny to explicitly disallow certain users from using cron.
If neither files exist, then only the super user is allowed to run cron. Well, that depends on the system specific configuration to be exact. Most configuration do not allow any users to run jobs, while some systems allow all users to run jobs by default.
So, the first step is to create a file named cron.allow in the /etc/ folder. Add the user name to this file in order to allow the user to run jobs.
Once the proper permissions has been set, the user should be able to modify and run jobs using the crontab command.

Autoit runas access denied

I need to copy a file in C:\Windows\System32\drivers\etc folder using a non-admin user.
I done a script using autoit and runas function but I receive "access denied"
How can I copy a file in C:\Windows\System32\drivers\etc using a non-admin user account?
First check that file you copy can be copied with basic batch script. Sometime overwrite is not possible due ownership rights.
Try that rights elevation code:
If Not IsAdmin() Then ;if not admin become admin
ShellExecute(#AutoItExe, $CmdLineRaw, #WorkingDir , "runas", #SW_SHOWNORMAL) ; "runas" - require admin privileges. i don't now how it works. ¯\_(ツ)_/¯ magic...
Else ;normal execution if already admin

Why does a new default directory have user executable permissions where as a new file only has user read and write permissions?

Noticed this when creating a new directory in unix, and was just curious as to why this is so.
Thanks
A new directory created by a user and owned by the user with full permissions is no big deal. However, a new file/program if executed accidentally or before configuration could have catastrophic results. So the designers decided to give you a layer of protection.
It also prevents other users from executing the file unless you specifically grant permission.
Because you need the executable permissions to naviguate into the directory.
So basic permissions allow user to read file (read file permission), and to access file in directory (directory execute permission).
Note that read permission on a folder allow user to list files in it. (But doesnt allow to read them unless execute permission is granted too as I said in the first place)
Basically, +x on a directory means that the user can 'execute it' hence change into it (replace user by group or other depending on position in permissions).
Hence drwxr--r-- means only user can change into directory. More here.
The directory needs to have executable permissions so you can do things such as cd into it. Also the executable permission lets you look into the directory for inode information of the files it contains.
More info can be found at this source.

Symfony2 login fails when session.storage.filesystem is set for storage_id

I'm trying to do some functional testing with PHPUnit but it requires that I add session.storage.filesystem for the storage_id option in config.yml.
This causes the login process to fail, for some reason. I get the following error in test.log :
Authentication request failed: Your session has timed-out, or you have disabled cookies.
Afterwards I'm redirected to the login page again. I'm certain that I have cookies enabled and that the application works without setting that option(with native session storage).
Could anyone tell me whether there is any solution for this issue?
Give a try at changing your file permissions for the cache folder. If they're not set properly , this is what will happen:
You develop stuff and test it through your web browser => your apache (or other server) will create the cache and will be the only one to have permissions on it
You start phpunit tests from the command line (different unix user) => the current unix user does not have write access to your cache folder and cannot store the sessions.
Immediate fix to validate that this is the case:
chmod -R 777 app/cache/
phpunit -c app/
If this is actually the case, then go check how to properly set the rights at: http://symfony.com/doc/current/book/installation.html#configuration-and-setup

Resources