Permission denied when i'm trying to use elasticsearch command

Hello there,
I am trying to configure basic security on my Elasticsearch production but i'm getting error when i try to launch a command from the path /usr/share/Elasticsearch/bin i'm getting this error

./elasticsearch-env: line 88: /etc/default/elasticsearch: Permission denied

here is the "ls -l" :

total 3472
-rwxr-xr-x 1 elasticsearch elasticsearch    2985 Jan  6 23:48 elasticsearch
-rwxr-xr-x 1 elasticsearch elasticsearch     501 Jan  6 23:48 elasticsearch-certgen
-rwxr-xr-x 1 elasticsearch elasticsearch     493 Jan  6 23:48 elasticsearch-certutil
-rwxr-xr-x 1 elasticsearch elasticsearch     996 Jan  6 23:48 elasticsearch-cli
-rwxr-xr-x 1 elasticsearch elasticsearch     443 Jan  6 23:48 elasticsearch-croneval
-rwxr-xr-x 1 elasticsearch elasticsearch    5522 Feb  2 14:14 elasticsearch-env
-rwxr-xr-x 1 elasticsearch elasticsearch    1828 Jan  6 23:48 elasticsearch-env-from-file
-rwxr-xr-x 1 elasticsearch elasticsearch     168 Jan  6 23:48 elasticsearch-geoip
-rwxr-xr-x 1 elasticsearch elasticsearch     184 Jan  6 23:48 elasticsearch-keystore
-rwxr-xr-x 1 elasticsearch elasticsearch     450 Jan  6 23:48 elasticsearch-migrate
-rwxr-xr-x 1 elasticsearch elasticsearch     126 Jan  6 23:48 elasticsearch-node
-rwxr-xr-x 1 elasticsearch elasticsearch     176 Jan  6 23:48 elasticsearch-plugin
-rwxr-xr-x 1 elasticsearch elasticsearch     441 Jan  6 23:48 elasticsearch-saml-metadata
-rwxr-xr-x 1 elasticsearch elasticsearch     439 Jan  6 23:48 elasticsearch-service-tokens
-rwxr-xr-x 1 elasticsearch elasticsearch     448 Jan  6 23:48 elasticsearch-setup-passwords
-rwxr-xr-x 1 elasticsearch elasticsearch     118 Jan  6 23:48 elasticsearch-shard
-rwxr-xr-x 1 elasticsearch elasticsearch     483 Jan  6 23:48 elasticsearch-sql-cli
-rwxr-xr-x 1 elasticsearch elasticsearch 3455027 Jan  6 23:48 elasticsearch-sql-cli-7.16.3.jar
-rwxr-xr-x 1 elasticsearch elasticsearch     436 Jan  6 23:48 elasticsearch-syskeygen
-rwxr-xr-x 1 elasticsearch elasticsearch     436 Jan  6 23:48 elasticsearch-users
-rwxr-xr-x 1 elasticsearch elasticsearch     332 Jan  6 23:48 systemd-entrypoint
-rwxr-xr-x 1 elasticsearch elasticsearch     356 Jan  6 23:48 x-pack-env
-rwxr-xr-x 1 elasticsearch elasticsearch     364 Jan  6 23:48 x-pack-security-env
-rwxr-xr-x 1 elasticsearch elasticsearch     363 Jan  6 23:48 x-pack-watcher-env

Thanks

i forgot to precise that i'm on ubuntu 20.04 and this is the 7.16.3 version of ES

What user are you running this command as?

I tried to su Elasticsearch but i still see my default user on the shell and it still doesn’t work

Checks who owns this directory (/etc/default/Elasticsearch) and if not Elasticsearch, assigns permission to this user and group:

sudo chown -R Elasticsearch:Elasticsearch /etc/default/Elasticsearch

Alternatively, run the command below:

sudo chmod +x /usr/share/Elasticsearch/bin/Elasticsearch

With your username, use the sudo command to run ./Elasticsearch

Ok the directory /etc/default/Elasticsearch is owned by the right user and group

-rw-rw---- 1 elasticsearch elasticsearch 1724 Feb  8 15:47 /etc/default/elasticsearch

then i run this command like you said : sudo chmod +x /usr/share/Elasticsearch/bin/Elasticsearch
then i run the command : sudo /usr/share/Elasticsearch/bin/Elasticsearch
and i got this error :

OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
[2022-02-11T14:43:15,503][ERROR][o.e.b.ElasticsearchUncaughtExceptionHandler] [arkoosnode] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
        at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:170) ~[elasticsearch-7.16.3.jar:7.16.3]
        at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:157) ~[elasticsearch-7.16.3.jar:7.16.3]
        at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:77) ~[elasticsearch-7.16.3.jar:7.16.3]
        at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:112) ~[elasticsearch-cli-7.16.3.jar:7.16.3]
        at org.elasticsearch.cli.Command.main(Command.java:77) ~[elasticsearch-cli-7.16.3.jar:7.16.3]
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:122) ~[elasticsearch-7.16.3.jar:7.16.3]
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:80) ~[elasticsearch-7.16.3.jar:7.16.3]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
        at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:107) ~[elasticsearch-7.16.3.jar:7.16.3]
        at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:183) ~[elasticsearch-7.16.3.jar:7.16.3]
        at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:434) ~[elasticsearch-7.16.3.jar:7.16.3]
        at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:166) ~[elasticsearch-7.16.3.jar:7.16.3]
        ... 6 more
uncaught exception in thread [main]
java.lang.RuntimeException: can not run elasticsearch as root
        at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:107)
        at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:183)
        at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:434)
        at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:166)
        at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:157)
        at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:77)
        at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:112)
        at org.elasticsearch.cli.Command.main(Command.java:77)
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:122)
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:80)
For complete error details, refer to the log at /var/log/elasticsearch/elasticsearch.log
2022-02-11 14:43:15,874409 UTC [3267] INFO  Main.cc@111 Parent process died - ML controller exiting

in the log it tells : Caused by: java.lang.RuntimeException: can not run Elasticsearch as root
Thanks

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.