How do I run my application as superuser from Eclipse?

后端 未结 9 1489
闹比i
闹比i 2020-11-29 09:35

I\'m running in to an error when I try to run my server application from Eclipse. The error is java.net.BindException: Permission denied. I think this is be

相关标签:
9条回答
  • 2020-11-29 09:36

    Assuming you are on Linux (*nix), How about starting your eclipse session via a sudo command?

    Such as

    sudo ~/eclipse/eclipse
    

    Now whatever you do from eclipse will have the sudo context?

    0 讨论(0)
  • 2020-11-29 09:37

    Another option would be to use iptables or ipfilter to forward port 80 to a port above 1024.

    (Can someone contribute a link to a practical and easy-to-understand explanation ?)

    0 讨论(0)
  • 2020-11-29 09:43

    If you use External tools (Run menu/External tools or an icon next to the Run/Debug icons on the toolbar), you can use any scripts or whatever you like. The scripts may give you elevated rights, or whatever.

    On the other hand, this way debugging the application can become very hard, as neither the Run nor Debug commands get associated with this External tool configuration. Maybe it is possible to connect the Eclipse debugger of the application, but I don't know, how that is possible.

    0 讨论(0)
  • 2020-11-29 09:48

    You can follow these steps to compile/debug applications as superuser.

    1. Rename your java-application

      sudo mv /usr/lib/jvm/java-6-openjdk/jre/bin/java /usr/lib/jvm/java-6-openjdk/jre/bin/java.ori

    2. Create following script and store it as /usr/lib/jvm/java-6-openjdk/jre/bin/java

      #!/bin/bash
      # file:  /usr/lib/jvm/java-6-openjdk/jre/bin/java
      # descr: Starter for jdk. Runs jdk as root when 
      #        cmd-line-arg "--run-as-root" is specified.
      #
      jre="/usr/lib/jvm/java-6-openjdk/jre/bin/java.ori"
      run_as_root=false
      args=
      
      # Filter command-line argument
      for arg in "$@"
      do
        case "$arg" in
        --run-as-root)  run_as_root=true
                        ;;
        *)              args="$args $arg"
                        ;;
      
        esac
      done
      
      # Remove leading whitespaces
      args=$(echo $args | sed -e 's/^[ \t]*//')
      
      if $run_as_root
      then
        echo "WARNING: Running as root!"
        gksu "$jre $args"
      else
        $jre $args
      fi
      
    3. Change the permissions to make it executable

      sudo chmod 0755 /usr/lib/jvm/java-6-openjdk/jre/bin/java

    4. Startup eclipse

    5. Go to Window->Preferences->Java->Installed JREs
    6. Duplicate java-6-openjdk to java-6-openjdk-root
    7. Edit JRE and add "--run-as-root" as Default VM Argument

    To run projects as root you need to follow these steps:

    1. Go to Project->Properties->Java Build Path
    2. Double-Click the JRE System Library and choose in Alternate JRE "java-6-openjdk-root"

    Note: The idea is from http://www.eclipse.org/forums/index.php/mv/msg/87353/724852/#msg_724852

    0 讨论(0)
  • 2020-11-29 09:51

    You may go this way

    1. create a Makefile with javac calls
    2. add the following line:
    setcap 'cap_net_admin=+ep' Server
    
    1. configure sudo to allow your Eclipse user to run setcap.

    So you will have a transparent debugging (no sudo wrapper - gdb ok). Cons: it is a local security breach.

    Solution:

    put this to /opt/my-stupid-eclipse

    #!/bin/sh

    setcap 'cap_net_admin=+ep cap_net_raw=+ep' $1

    chmod +x this script and whitelist it on sudo config.

    username ALL=(ALL) NOPASSWD: /opt/my-stupid-eclipse

    Add it to your makefile, specify path to your Server binary.

    Now you have pretty strange but secure script, that cannot be changed by other users... and still a little breach for replacing Server binary with any malicious code, that will gain caps, so no filename check/stricts will help.. can $1 be contaminated with bash commands, no? Guess, no.

    0 讨论(0)
  • 2020-11-29 09:51

    You can use Remote Java Application mechanism for this.

    1. Create Debug configuration for Remote Java Application section in Run -> Debug configurations...
    2. Set your project name
    3. Choose Connection type as Standard (Socket Attach)
    4. Configure Connection properties parameters for your binding (for you it will be localhost and 443).
    5. Set breakpoint in your app (e.g. at the beginning of the main method)
    6. Run your app from terminal as superuser with following params: -java Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=443 MyApp
    7. Hit debug button in Eclipse for early created Remote Java Application
    8. You code should be stopped on breakpoint in Eclipse!
    0 讨论(0)
提交回复
热议问题