maven: bash mvn permission denied - linux

This is what I'm seeing:
mvn
bash: /usr/local/apache-maven/apache-maven-3.1.1/bin/mvn: Permission denied
my bash file:
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# User specific aliases and functions
JAVA_HOME=/usr/java/default
export JAVA_HOME
HADOOP_HOME=/usr/share/491s14/hadoop
export HADOOP_HOME
PATH=$PATH:$HOME/bin:$HADOOP_HOME/bin
export PATH
export M2_HOME=/usr/local/apache-maven/apache-maven-3.1.1
export M2=$M2_HOME/bin
PATH=$M2:$PATH
ls command:
ls -l /usr/local/apache-maven/apache-maven-3.1.1/bin/mvn
-rw-r--r--. 1 root root 5806 Feb 21 11:33 /usr/local/apache-maven/apache-maven-3.1.1/bin/mvn
file command:
file /usr/local/apache-maven/apache-maven-3.1.1/bin/mvn
/usr/local/apache-maven/apache-maven-3.1.1/bin/mvn: POSIX shell script text executable

Your permission shows that you can't execute that file. Modify permissions for that file. If you want all the users in the machine should be able to execute that file, then do this :
chmod a+x /usr/local/apache-maven/apache-maven-3.1.1/bin/mvn

/usr/local/apache-maven/apache-maven-3.1.1/bin/mvn does not have the execute permission. This should be able to fix it:
chmod a+x /usr/local/apache-maven/apache-maven-3.1.1/bin/mvn

sudo chmod 777 <mvn location> fixed it. Man I suck at linux :P

You can try chmod +x <your-mvnw-file>. It does work.

Related

Not able to execute the commands in same sudo session

Not able to execute below touch command in same session of user - weblogic. Instead below touch command is executing on user - djaiswa2 and is failing [Because it is trying to access the path whose owner is weblogic].
[djaiswa2#cdcesb01 tmp]$ cat test.sh
#!/bin/bash
sudo su - weblogic;
touch /opt/middleware/.ssh/authorized_keys;
chmod 755 /opt/middleware/.ssh/authorized_keys;
[djaiswa2#cdcesb01 tmp]$ sh -x test.sh
+ sudo su - weblogic
Last login: Thu Aug 26 00:38:06 EDT 2021 on pts/0
-bash-4.2$ exit
logout
+ touch /opt/middleware/.ssh/authorized_keys
touch: cannot touch ‘/opt/middleware/.ssh/authorized_keys’: Permission denied
+ chmod 755 /opt/middleware/.ssh/authorized_keys
chmod: cannot access ‘/opt/middleware/.ssh/authorized_keys’: No such file or directory
You need to use su command with -c option to specify the commands to be executed.
for exampe:
sudo su - weblogic -c "touch /opt/middleware/.ssh/authorized_keys; chmod 755 /opt/middleware/.ssh/authorized_keys"

Remove ".bash_aliases" with bash script

In my .bashrc I'm using .sh script for easily configuring newly installed Debian. But while trying to
rm -f ~/.bash_aliases
wget https://raw.githubusercontent.com/.../.bash_aliases
rm -f ~/.bashrc
wget https://raw.githubusercontent.com/.../.bashrc
it's just omitting those line?
File is with permission chmod +x ./script.sh and run by sudo ./script.sh
What could possibly be wrong?
(In final code there is full link, files are being downloaded as .bashrc.1 and .bash_aliases.1)
Don't use sudo unless you have a good reason.
When you run sudo ./script.sh it runs as root, so ~ refers to root's home directory /root instead of your user's home directory.
Just run ./script.sh instead, so that it runs as you and modifies your own home directory.

Tomcat not starting in linux ---permission denied to run startup.sh

I pasted tomcat folder in Linux machine. User is root . When I go to bin folder and execute ./startup.sh I'm getting an error:permission denied. [This is what I got]
How to rectify this issue.
give:
chmod -R 777 startup.sh
Then error will come as:Cannot find ./catalina.sh
then give:
chmod -R 777 catalina.sh
Tomcat will start.
the problem was because there was no permission for executing. u can see if permission is there or not by giving:
ls -l
As color of file name is white, I suppose file is not executable; try the following command
ls -l
It gives you file list with its permission. Try using command
chmod a+x startup.sh
If still permission denied. Try
sudo chmod a+x startup.sh
Then try using
./startup.sh
If still permission denied. Then try
sudo ./startup.sh
Hope it will be helpful.
Verify, that your filesystem with the new tomcat folder isn't mounted with "noexec". Please run a "ls -l", "file start.sh" and a "head start.sh" .
Tom
It is also worthwhile to check which bash you are using with
which bash
This is because you might see the error
Cannot find ./catalina.sh
when your bash is /usr/bin/bash but is working perfectly fine when bash is /usr/bash

chmod: changing permissions of ‘my_script.sh’: Operation not permitted

when I'm trying to make shell script that error is shown ,what i must do ??
[rehamadel#localhost bin]$ sudo vi my_script.sh
[sudo] password for rehamadel:
[rehamadel#localhost bin]$ ls -l my_script.sh
-rw-r--r--. 1 root root 52 Jul 30 19:25 my_script.sh
[rehamadel#localhost bin]$ chmod u+x my_script.sh
chmod: changing permissions of ‘my_script.sh’: Operation not permitted
Resolving the operation not permitted error:
sudo chmod u+x my_script.sh
You created the file via:
sudo vi my_script.sh
# editing
This means, the owner and group of the file is root. You are not allowed to change files of it by default. You need to change permission (chmod does it) or change the owner:
sudo chown you:yourgroup my_script.sh
This should do it. Save the trouble, without creating the file via sudo.
You've created file my_script.sh with the root user as the owner (because you used sudo), which is why you're not permitted to change the permissions as yourself.
Thus, use sudo chmod u+x my_script.sh, but note that that will make the file only executable for the root user.
To make the file executable by everyone, use sudo chmod a+x my_script.sh.
I faced this error because I uploaded the files via winscp and was trying to change permission on Linux window.
I was able to change permissions via winscp.

Exec script as root in autostart

I need to launch a log on script. This log on script contain several commands like : *cp, ln, and chown.*
But "chown" need to be root to be efficient. So my script is doing well, except the "chown" command.
My environnement :
Debian Jessie, LXDE.
My script (in /usr/local/bin/transfertPOL.sh) :
#!/bin/bash
#transfert de POL au démarrage de la session
groupe=$(id -gn $1)
uid=$(id -u $1)
POL=/var/POL
home=$(eval echo ~$1)
lien=$home/.PlayOnLinux
#changement de propriétaire du dossier
sudo chown -h -R $1:$groupe $POL
ln -s $POL $lien
sudo chown -h -R $1:$groupe $lien
#Copie des raccourcis sur le Bureau
cp --preserve=ownership $POL/shorcuts/*.desktop $home/Desktop
My Desktop Entry in /etc/xdg/autostart/transfertPOL.desktop :
[Desktop Entry]
Type=Application
Exec=sh /usr/local/bin/transfertPOL.sh
The Exec, I tried several things :
Exec=sh /usr/local/bin/transfertPOL.sh #Work, but the chown don't
Exec=/bin/bash/ -c "sudo /usr/local/bin/transfertPOL.sh" #doesn't work
Exec=sudo sh /usr/local/bin/transfertPOL.sh #Work, but the chown don't
For this one, I've created a /etc/sudoers.d/transfert with
%users ALL=NOPASSWD: /usr/local/bin/transfertPOL.sh
The script is a symbolic link to PlayOnLinux local folder. Each users need to access to this specific POL folder. So when a user is logging, the chown is changing folder rights.
Do you have any idea to help me ?
Thanks
You are calling sh in the Exec command:
Exec=sudo sh /usr/local/bin/transfertPOL.sh
So the sudoers entry:
%users ALL=NOPASSWD: /usr/local/bin/transfertPOL.sh
wont run with root privileges.
You probably want to make your script executable:
sudo chmod +x /usr/local/bin/transfertPOL.sh
And change the Exec command to:
Exec=sudo /usr/local/bin/transfertPOL.sh
BUT: We got groups for that in Linux, try setting the correct group permissions on the files you want to read/write. You wont need that script at all then.

Resources