How to open a desktop entry as root? - bash

I have a desktop entry placed in usr/share/applications that runs a Java jar and looks something like:
[Desktop Entry]
Encoding=UTF-8
Exec=pkexec /usr/bin/java -jar something-something.jar
Icon=default.png
Type=Application
Terminal=false
Name=foo
GenericName=bar
StartupNotify=false
Categories=Game
I need to run the JAR as root, so I tried using pkexec to have a GUI password prompt appear so I can run the JAR as sudo (I am using Ubuntu 18). However, it would not work and when I tried to open the desktop entry in the terminal (using something like xdg-open) I got: Refusing to render service to dead parents
I believe the problem is with my using pkexec. While I would be interested to know why pkexec does not work for my usage, I would like to know what I can do to run the JAR with sudo from the GUI? That way, when I click on the desktop entry from the menu, a password prompt appears.
Edit:
Actually, I've been using gtk-open and getting the dead parents error. xdg-open results in the desktop entry simply being opened in vim.

pkexec is part of PolicyKit, which allows a finer distribution of rights. To execute programs with graphical user interface using pkexec, you can use the following call:
pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY /usr/bin/java -jar something-something.jar

Related

Apache Guacamole starting intial wine program

I am trying to setup a remote desktop using Apache Guacamole on Ubuntu 20.4 but I only want the initial program accessible to the user. The program is a Windows program and I am using WINE.
So far I have tried invoking wine via a bash script. And then placing that script path in the initial program settings in the connection settings of Apache Guacamole.
The initial program path looks like /home/frank/launchprogram.sh in the guacamole connection settings.
The launchprogram.sh bash script looks like below. I simply copied the command settings in the shortcut that is on my desktop. For simplicity I have it chmod 777.
#!/bin/sh
env WINEPREFIX="/home/frank/.wine" wine C:\\windows\\command\\start.exe /Unix /home/frank/.wine/dosdevices/c:/users/Public/Desktop/myprogram\ V4.lnk
The above script works fine from the terminal when on the desktop. But not with Guacamole.
I have also tried in the bash script
WINEPREFIX="/home/frank/.wine"
wine "/home/frank/.wine/drive_c/Program Files/myprogramfolder/myprogram.exe"
and it doesn't work.
If I simply put
wine myprogram.exe and run it in the same directory it works. But not in others.
What am I doing wrong?

"Unable to access jarfile jenkins.war" getting this error while run the cmd "java -jar jenkins.war" in OS- windows 7

"Unable to access jarfile jenkins.war" getting this error while run the cmd "java -jar jenkins.war" in OS- windows 7
How can I solve?
i did installation as per what showed in youtube
Command java -jar jenkins.war in Win7 command line require administrator permission.
Right click on the cmd icon and choose the Run as administrator option.
It worked for Windows 8 too.
I also faced this issue after I updated the jenkins version.
The error message was found in <jenkins_dir>/jenkins.error.log
Resolved Step:
Download your jenkins.war at https://updates.jenkins-ci.org/download/war/
Put jenkins.war to your jenkins work directory
Go Jenkins Service and restart it
Enjoy it!
Ref: Cannot start Jenkins
Make sure you are executing that command in the folder where jenkins.war is actually installed.
Also check if the file is readable, and not preempted by another process (you can check that with Process Explorer)
Finally, double-check the size of jenkins.war, to see if the download was complete, and the file is not corrupted (incomplete or small size): see the list of jenkins.war released.
Open Command Prompt as Administrator in Windows . Go to the directory where Jenkins is installed. and stop the Jenkins service first, using jenkins.exe stop
type the command to change the port using, java -jar jenkins.war
You will be able to access the .war file of Jenkins.
I had the same issue. What worked for me was adding .jar to the file name, like
java -jar jenkins.war.jar
in case that you face an error that says, "Failed to listen on port 8080"
There is an answer here that worked for me, by pasting the following on cmd,
java -jar jenkins.war.jar --ajp13Port=-1 --httpPort=9090
do not create a folder for jenkins.war file
store it right inside downloads direction
then go to your terminal go to downloads direction not to jenkins.war file direction
then type java -jar jenkins.war
it will work

Run jar file without admin rights

I have a runnable jar file, that I start with
java -jar myFile.jar
on Windows. A customer stated that he had problems starting the application (which is this jar file wrapped into an executable). I have the suspicion that it has something to do with admin rights. So I'd like to run my jar file without admin rights for testing purposes (because this way I get the System.out/err which helps greatly for debugging).
I realize that I can just create a non-admin account and start the application there, but I'd like to know if there is a way to specifically start a jar from an admin account so that it doesn't have admin rights in the console. Or alternatively: Is there a way to open up a console that has no admin rights from an admin account?
The customer uses Windows XP, so this is the operating system that I can use. (Although if you know something in a newer Windows like Win7, I appreciate it if you would tell me too).
EDIT: To clarify: I am looking for something like this
java -jar -runWithoutAdminRights myFile.jar
or
start /runWithoutAdminRights java -jar myFile.jar
or a way to open up a non-admin console from an admin account.
The Runas command definitely looks like the way to go.
I believe the way to go about this would be to first check the trust level options available to you:
runas /showtrustlevels
You should get something like the following:
C:\Windows\system32>runas /showtrustlevels
The following trust levels are available on your system:
0x20000 (Basic User)
You would then take the value for "Basic User" and run something like the following to start java:
runas /trustlevel:0x20000 "java -jar myFile.jar"
You can follow the below steps:
Log in as the Administrator
Open the command line
Go to System32 folder (cd C:/Windows/System32)
execute: runas /user:computer_domain_name\user1 cmd
You will be asked to provide the user1's password. Afterwards a new command line opens with the user1's rights.
I have tried it and it worked.
In conclusion you can write a very simple batch which performs the steps 2,3,4 automatically so that when you click it, a command line will open with the rights of another user.
I hope this helps.
edit registry is best way to run jar file with administrator automatically.
is easy if you have setup for java application.
go to following path in registry:
HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers
create a key(String Value) with following specification:
ValueName: java path+javaw.exe(example c:\program files\java\jre7\bin\javaw.exe)
ValueData: "WINXPSP3 RUNASADMIN"
Now All Jar Files Runs to Administartor

How to run Hadoop on Cygwin with proper credentials to enable setting file permissions, etc.?

I cannot change the permissions on files when I run Hadoop in Cygwin:
java.io.IOException: Failed to set permissions of path: \tmp\hadoop-James\mapred\staging\James-1143336710\.staging to 0700
From what I've gathered you can't really run Cygwin as root since Windows doesn't really have a notion of root (reference), and I've tried to run Cygwin as the Administrator user but this option isn't available to me when I right click on the Cygwin shortcut in Windows XP (I've also tried changing the Cygwin shortcut's properties to allow me to run as another user but that option is disabled).
Can anyone advise me as to how I can get past this issue? Thanks in advance for your help.
Here is a simple-to-use workaround for this particular problem:
https://github.com/congainc/patch-hadoop_7682-1.0.x-win
This issue is not about file permissions per se. Rather, it is an issue with the Java VM's support for setting file permissions on Windows, and an intransigent attitude among the Hadoop committers not to work around the problem. See HADOOP-7682 for the gory details:
https://issues.apache.org/jira/browse/HADOOP-7682
run ssh-host-config. it will set up the prvileged user "cyg_server" and set up sshd
as a windows service.
in "/etc/passwd" give the user a home "/home/cyg_server" and shell "/bin/bash".
create a password for the user. then create the ssh keys and add them to
~/.ssh/authorized_keys.
start the windows service. in a cygwin shell, "ssh cyg_server#localhost".
--- edit ---
forgot to mention: when you create the password for the cyg_server user, you need a root cygwin shell (run cygwin bash as Administrator). also give the user a valid shell (/bin/bash).

How do you edit files over SSH?

I program with eclipse and sometimes use GUI text editors like SciTE or vim. However, I'm at a point in a project that requires me to edit files over a ssh connection in a 80 column SSH window.
Since I have to (* shiver*) sudo vim before I can open the file I'm not sure how to open the file in an editor outside the terminal (that would allow me to see the text wider than 80 columns). If the command line was larger then I guess using straight vim wouldn't be a problem.
I'm at a loss of how to deal with this situation and how I could turn this nightmare into a manageable coding environment.
Maybe you should simply mount the remote filesystem to your local machine and then use whatever editor you like. If running a Debian derivative, install sshfs
sudo apt-get install sshfs
and then mount the remote filesystem ( issue on your local machine )
mkdir ~/remote_code
sshfs $USER#remote.example.com:/home/$USER/code ~/remote_code
Once this is done you can access the code in ~/remote_code w/ any of your GUI tools and without the bandwidth overhead of using ssh -X (however you still need a good connection w/ a low ping time).
PS: When using ssh I can make the terminal as wide as it fits my screen and then use its full width, so I fear I don't completely understand your issue.
WinSCP is a SSH client ftp-like. The default editor is primitive but can be change.
There are various options.
You can make the terminal larger. ;)
If you have a graphical environment installed on the machine you are ssh'ing into, you can login with ssh -X (or xdeep-putty if you are on Windows) to enable window forwarding. You can then run your favourite editor on the remote machine, whose graphical output is forwarded.
Finally, you can mount the ssh connection into your file system, using for example fuse (similar options might exist for non-linux operating systems). That allows you to access any file on the remote machine as if it were in your filesystem, with your favourite editor, locally.
I'm not 100% sure if this works for files owned by root, but if your desktop is KDE & your remote system is Linux (or pretty much any form of *nix), you can get konqueror to access the remote machine using the "fish://" protocol. From there you can open the file from konqueror using kate, or your preferred editor, and konqueror will take care of copying the file to your local machine and copying it back when you save.
Failing which the X11 forward is a good option, but X11 over ssh to remote sites can be slow. "ssh -X -C" compresses the data stream and can give better performance.
Notepad ++ has a plugin for editing files remotely over ssh. I've used it before, but I definitely prefer Kate on KDE using the fish protocol.
http://www.inmotionhosting.com/support/website/ftp-client-setup/connect-ftp-notepad-plus
Forward your X11 session to your terminal.
http://dragonwall.net/xdeep-putty.html
This probably belongs on superuser.com.
You might try the Komodo editor. It has a feature to load a 'remote file' over ssh. It's really convenient.
Emacs and ange-ftp.
If you're on Ubuntu, go to Nautilus (file explorer), connect to server (adding sftp:// to the hostname), then voila! You can easily launch gedit to edit your files now.
On Windows, you can use MobaXterm ( http://mobaxterm.mobatek.net ): it has a built-in SSH client with a very useful "SFTP browser".
As soon as you connect to your remote server using SSH, you will see your remote files displayed in this graphical SFTP browser. Just double-click on your files and you will be able to edit them directly on your remote server through SFTP.
I use Cyberduck and Sublime Text 2
FileZilla did the trick for me. Notepad++ can be used with it which is awesome.
If you using windows, try Editplus. It's not free but allows you to open files directly over scp. Custom syntax files are coming really handy, too.
Recent versions of ultraedit do exactly what the OP is asking for elegantly (IDM software, v10 and up support SSH iirc). I do most of my coding remotely like that, been using it for years, works great with no intermediate files etc. Obviously it also does FTP etc too if you're so inclined.
I actually found this page whilst looking for a linux equivalent of ultraedit..
If you are more GUI-oriented and use one of the more newbie-friendly Linux distros like Ubuntu or Mint, this is another option and does not require any more installations.
You should have nemo as your default file manager. It may not be called "Nemo" on the menu, so go under Help > About of your file manager ("Files" app) to see.
In nemo, go to File > Connect to server, enter your remote machine's details (SSH's default port is 22), and then open the files just like any file on your local machine, with whatever editor you prefer. You can even close Nemo and continue working in your editor.
From the address bar, it seems to be using the sftp protcol.
Just be aware that if your remote host has an inactivity timeout for the SSH connection, this will also prevent you from saving changes in the editor after the timeout has dropped the connection...
Since sshfs is not supported in WSL at the moment, the tool that worked for me is sshfs-win.
Installation Steps
Go here and click "download winfsp"
Install it
Go here and download the installer
Install it
Open windows explorer and right-click "This PC" > "Map Network Drive..."
Select a drive letter (B:), type in "\\sshfs\debian#10.13.100.36" and click Finish
Boom, done. Now you can have a B: drive on your computer and just do whatever with those files. Open them with VSCode, delete them, whatever you like
If you work in IntelliJ IDEA, you can use Friendly Terminal plugin instead of the native terminal. It allows to open and edit remote files in IntelliJ IDEA editor. Video

Resources