Can't run npm-installed packages as user - node.js

Earlier this afternoon I installed Node.js on Fedora 16.
user#$ sudo yum localinstall --nogpgcheck http://nodejs.tchol.org/repocfg/fedora/nodejs-stable-release.noarch.rpm
user#$ sudo yum install nodejs-compat-symlinks npm
Then I installed a package with npm. Every package I've installed with npm on Fedora (this isn't my first time) has involved something like the following process. Read it and weep. Clearly, this is hackish and wrong, but when I decide to install less or any other npm package, I have to go through the same procedure. Why? What is broken about my environment or approach?
user#$ sudo npm install -g jslint
[... this works ... kind of]
user#$ jslint
bash: jslint: command not found
user#$ sudo su
root#$ jslint
No files specified.
Usage: /bin/jslint ... [works]
root#$ which jslint
/bin/jslint
root#$ ls -l jslint
lrwxrwxrwx. 1 root root 38 Jul 15 14:58 /bin/jslint -> /lib/node_modules/jslint/bin/jslint.js
root#$ cd /lib/node_modules; ls -l
...
drwxr-xr-x. 2 root root 4096 Jul 15 14:22 inherits
drwxr-xr-x. 2 root root 4096 Jul 15 14:22 ini
drwx------. 6 nobody usergroup 4096 Jul 15 14:58 jshint
drwxr-xr-x. 3 root root 4096 Jul 15 14:22 lru-cache
...
root#$ find . -type d -print0 | xargs -0 chmod 755
root#$ ls -l
...
drwxr-xr-x. 2 root root 4096 Jul 15 14:22 inherits
drwxr-xr-x. 2 root root 4096 Jul 15 14:22 ini
drwxr-xr-x. 5 nobody usergroup 4096 Jul 15 15:32 jslint
drwxr-xr-x. 3 root root 4096 Jul 15 14:22 lru-cache
...
root#$ su user
user#$ jslint
o files specified.
Usage: /bin/jslint [now it finally works]

Recent versions of npm switch to user "nobody" as a security measure if it's being run with sudo privileges. Try doing global installs while logged in as root, rather than using sudo.

Related

suid is not honoured inside docker container

I downloaded sudo in my DockerFile
RUN yum -y update &&
yum -y install which sudo
I have set suid bit on it
RUN chown root:root /usr/bin/sudo
RUN chmod 4755 /usr/bin/sudo
In container I see lot of binaries with suid bit set
root#89f28b09dee0 go]# ls -la /usr/bin/* | grep rwsr
-rwsr-xr-x 1 root root 73888 Aug 9 2019 /usr/bin/chage
-rwsr-xr-x 1 root root 78408 Aug 9 2019 /usr/bin/gpasswd
-rwsr-xr-x 1 root root 44264 Aug 9 2019 /usr/bin/mount
-rwsr-xr-x 1 root root 41936 Aug 9 2019 /usr/bin/newgrp
-rwsr-xr-x 1 root root 27856 Aug 9 2019 /usr/bin/passwd
-rwsr-xr-x 1 root root 32128 Aug 9 2019 /usr/bin/su
-rwsr-xr-x 1 root root 147320 Aug 9 2019 /usr/bin/sudo
-rwsr-xr-x 1 root root 31984 Aug 9 2019 /usr/bin/umount
Other binaries which are part of base image works seelessly
[test#89f28b09dee0 go]$ passwd
Changing password for user test.
Changing password for test.
(current) UNIX password:
But sudo fails
sudo
sudo: effective uid is not 0, is /usr/bin/sudo on a file system with the 'nosuid' option set or an NFS file system without root privileges?
[test#89f28b09dee0 go]$
Most of search on internet says it may be because of filesystem permission but other binaries are working fine from same location with suid bit set.

Why are directories I create owned by root:myNonPrimaryUserGroup?

My Ubuntu (WSL) user foo used to have primary group foo but I changed this to root. Still, when I sudo mkdir /bar the directory is owned by root:foo and not by root:root. Why?
[foo#mymachine]$ groups
root adm dialout cdrom floppy sudo audio dip video plugdev netdev lxd
[foo#mymachine]sudo mkdir /bar
[foo#mymachine]$ ls / | grep bar
drwxrwxr-x 1 root foo 512 Jun 14 17:40 bar/
UPDATE - This is a WSL/Ubunto Issue
I have just tried to reproduce the issue in CentOS and I can't.
I created b directly as myself (it's correctly owned by foo:root) and when I did sudo mkdir c this was also correctly owned by root:root.
drwxr-xr-x 2 foo root 6 Jun 15 14:30 b/
drwxr-xr-x 2 root root 6 Jun 15 14:31 c/
However, in WSL Ubuntu 16 the problem is definitely there:
drwxrwxrwx 1 foo root 512 Jun 15 14:34 b/
drwxr-xr-x 1 root foo 512 Jun 15 14:34 c/
sudo -g root mkdir bar
-g allows to choose the group in sudo command.

Tomcat installed folder access is denied on linux

Please find below set of cmds & outputs
[ec2-user#ip-172-31-38-218 opt]$ ls -al
total 9416
drwxr-xr-x 3 root root 4096 Nov 7 13:52 .
dr-xr-xr-x 25 root root 4096 Nov 7 13:16 ..
-rw-r--r-- 1 root root 9625824 Sep 4 22:52 apache-tomcat-8.5.34.tar.gz
drwxr-xr-x 5 root root 4096 Aug 11 01:26 aws
[ec2-user#ip-172-31-38-218 opt]$ sudo groupadd tomcatgrp
[ec2-user#ip-172-31-38-218 opt]$ sudo useradd -s /bin/false -g tomcatgrp -d /opt/tomcatfolder tomcatuser
[ec2-user#ip-172-31-38-218 opt]$ ls -al
total 9420
drwxr-xr-x 4 root root 4096 Nov 7 13:53 .
dr-xr-xr-x 25 root root 4096 Nov 7 13:16 ..
-rw-r--r-- 1 root root 9625824 Sep 4 22:52 apache-tomcat-8.5.34.tar.gz
drwxr-xr-x 5 root root 4096 Aug 11 01:26 aws
drwx------ 2 tomcatuser tomcatgrp 4096 Nov 7 13:53 tomcatfolder
Now, when I run the cmd I am getting Permission denied as follows
[ec2-user#ip-172-31-38-218 opt]$ cd /opt/tomcatfolder/
-bash: cd: /opt/tomcatfolder/: Permission denied
Can you please help in resolving this above issue..?
I followed instructions of installing Tomcat from this link how-to-install-apache-tomcat-8-on-centos-7
It seems you are the ec2-user, but the directory is owned by tomcatuser and the permissions on the directory do now allow other users or groups to read it.
Try sudo chmod 755 /opt/tomcatfolder/ and then cd into it.
That will add read and execute permissions to the directory.

Executing Karma giving permission denied error

I installed karma locally using
npm install karma --save-dev
and then i tried
$ ./node_modules/karma/bin/karma start
Then i get this error
vagrant#development:$ ./node_modules/karma/bin/karma start
-bash: ./node_modules/karma/bin/karma: Permission denied
vagrant#development:$ ls -liah ./node_modules/karma/bin/
total 4.0K
54696 drwxrwxr-x 1 vagrant www-data 102 Nov 17 19:24 .
54688 drwxrwxr-x 1 vagrant www-data 544 Nov 17 15:57 ..
54697 -rw-rw-r-- 1 vagrant www-data 50 Nov 15 02:43 karma
What can be the reason
http://karma-runner.github.io/0.12/intro/installation.html
vagrant#development:$ sudo chmod +x ./node_modules/karma/bin/karma
vagrant#development:$ ls -liah ./node_modules/karma/bin/
total 4.0K
54696 drwxrwxr-x 1 vagrant www-data 102 Nov 17 19:24 .
54688 drwxrwxr-x 1 vagrant www-data 544 Nov 17 15:57 ..
54697 -rw-rw-r-- 1 vagrant www-data 50 Nov 15 02:43 karma
Your ./node_modules/karma/bin/karma executable does not have execution privileges for your user. You can chmod it to give you the right privileges with:
$ chmod +x ./node_modules/karma/bin/karma
To avoid this in the future, simply install it with npm install -g karma-cli (globally).

linux PATH not working

I dont know why rbenv command do not work.. T^T
only work when 'cd /usr/local/.rbenv/bin && ./rbenv'
myggul#ubuntu:~$ echo $PATH
/usr/local/java/bin:/usr/local/.rbenv/bin;/home/myggul/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
myggul#ubuntu:~$ cd /usr/local/.rbenv/bin
myggul#ubuntu:/usr/local/.rbenv/bin$ ll
total 12
drwxrwxr-x 2 myggul myggul 4096 Jul 16 16:11 ./
drwxr-xr-x 7 myggul myggul 4096 Jul 16 16:11 ../
lrwxrwxrwx 1 myggul myggul 16 Jul 16 16:11 rbenv -> ../libexec/rbenv*
-rwxrwxr-x 1 myggul myggul 724 Jul 16 16:11 ruby-local-exec*
myggul#ubuntu:/usr/local/.rbenv/bin$ rbenv
The program 'rbenv' is currently not installed. You can install it by typing:
sudo apt-get install rbenv
myggul#ubuntu:/usr/local/.rbenv/bin$ cd ~
myggul#ubuntu:~$ rbenv
The program 'rbenv' is currently not installed. You can install it by typing:
sudo apt-get install rbenv
You have a semicolon in your PATH which should be a colon.

Resources