4

the problem

I installed IntelliJ IDEA on my system (to /opt/jetbrains), and want it to be able to modify its files (do self-updating) without enabling any other process to modify them.


the configuration

I've come up that I will need a system user, to whom the /opt/jetbrains directory will belong to, and I will run IDEA as that user:

# Set up things
sudo mkdir /opt/jetbrains
sudo adduser --system --home /opt/jetbrains jetbrains
sudo chown jetbrains /opt/jetbrains

# Install IDEA
wget https://download.jetbrains.com/idea/ideaIU-2017.1.2.tar.gz -O idea.tar.gz
sudo -u jetbrains tar -xzf idea.tar.gz -C /opt/jetbrains/
rm idea.tar.gz

# Configure idea.desktop
# set the 'Exec' line, to run as user jetbrains

what i tried

I have read Run a shell script as another user that has no password

I tried the following, but I got an error, as well as a password prompt.

  • sudo su -c "/opt/jetbrains/idea-ultimate/bin/idea.sh" -s /bin/sh jetbrains
  • sudo -u jetbrains /opt/jetbrains/idea-ultimate/bin/idea.sh

Both output:

No protocol specified

Start Failed: Failed to initialize graphics environment

java.awt.AWTError: Can't connect to X11 window server using ':0' as the value of the DISPLAY variable.
  at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
  at sun.awt.X11GraphicsEnvironment.access$200(X11GraphicsEnvironment.java:65)
  at sun.awt.X11GraphicsEnvironment$1.run(X11GraphicsEnvironment.java:115)
  at java.security.AccessController.doPrivileged(Native Method)
  at sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:74)
  at ...

I also tried gksu -w -u jetbrains gksu /opt/jetbrains/idea-ultimate/bin/idea.sh, but that prompted me a password - of user jetbrains, who obviously has no password.

  • Probably you want to install the IDE into the home of that new user, instead of /opt. However, running it with that user will give you problems when you try to modify projects into your home directory. – Andrea Lazzarotto May 06 '17 at 15:26

1 Answers1

4

It's late, but hopefully it helps someone. I'm doing this:

xhost +SI:localuser:foxx1337 && sudo -u foxx1337 /opt/jetbrains/idea-ultimate/bin/idea.sh

This is based on the wonderful reply sim gave here - https://unix.stackexchange.com/questions/108784/running-gui-application-as-another-non-root-user

foxx1337
  • 141
  • 1
    As an extra, do not forget to allow your user to sudo with no password prompt to the target user (otherwise the command can't be used in an X session). – foxx1337 Dec 16 '17 at 00:02