Opening programs on Raspberry Pi from terminal - terminal

When I first set up my Rasbperry Pi, I had it running with its own keyboard, mouse and monitor, and I could easily open applications using the terminal (e.g. python idle, etc.).
A few weeks ago I tried setting up X11 Forwarding to my windows machine using Xming and it worked great. But yesterday I tried opening Python IDLE and got the following message:
$ idle
Traceback (most recent call last):
File "/usr/bin/idle", line 5, in <module>
main()
File "/usr/lib/python2.7/idlelib/PyShell.py", line 1545, in main
root = Tk(className="Idle")
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1813, in __init__
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: couldn't connect to display "localhost:0.0"
I tried going back to using the Pi directly (mouse, keyboard and monitor attached) and got the same message. Even more mysteriously, my friend's account on the same Pi works fine.
The only remedy I can find is that manually setting the DISPLAY variable solves this completely (when working locally):
$ export DISPLAY=:0
But I don't have time to make this change every time. Is there something I can change in the configuration files to do this? And how can I fix my X11 Forwarding? Any help is appreciated.
**Please note: IDLE is just an example, this is true for any programs with GUIs including the epiphany browser.

You could append that command to /etc/rc.local to have it run every time you boot the machine.

Related

Why are my bash scripts refusing to run until I type 'exit' ever since I used 'script /dev/null'?

I am working on a cluster, the 'home' machine of which runs Linux version 2.6.38.4 on Debian 4.3.2-1.1. Other machines on the cluster run more recent versions of Linux (3.x.x.x) but on differing flavours (some Redhat, some Debian etc).
As usual, I transferred to chos 8 on one of these machines and set a script running in a screen, but the server began denying that there were any sockets available when I went to reattach it. I followed advice I found online and typed ‘script /dev/null’ in order to retrieve my screens, but it keeps happening. Also, when I start a new screen now, the command prompt is preceded by ‘(base)’.
Now, if I try to run a bash script on anything other than the home machine, the scripts won't run until I follow the command with 'exit', as follows:
bash ~/DAPHNIA/Scripts/compare_BUSCO_depths.sh 2 21 3 3 2-WGS_Clone_21_CGCTATGT-GTGTCGGA_L001;
exit;
The contents of the script don't seem to matter - this irritating quirk now happens regardless of the script being run.
Does anybody have any idea a) what has caused this, and b) how I can fix it, please?

Error protocol and QXcbConnection when I run a game after update to Debian Testing Buster

I was playing my game normally before the update, I was at Debian 9.3 Stretch.
After update I try to run the game with the same command.
bash start-tibia.sh
And Output this:
No protocol specified
QXcbConnection: Could not connect to display :0
Aborted
I don't know why this happening.
My system: enter image description here
Important if I run the application with a normal user it works, but with the root user isn't work.
Any helps would be appreciated. :B
-Melt

Cannot open graphical application through command line?

I am having trouble opening graphical applications in linux (Sublime Text 2 in this case) through the terminal. I am using Fedora 17. I get this error for other graphical applications that I try to open up through the command line as well.
[root#computer djproject]# sublime settings.py
No protocol specified
(sublime:4202): Gtk-WARNING **: cannot open display: :0
Also, I get the same type of error when I try to do:
sudo sublime
Note in the command above I was logged in as a regular user without root access. Also 'sublime' is mapped to Sublime Text 2, and I have tested it before in other scenarios, so it is not the problem. Also, I have set this particular user up as a valid sudoer and the sudo command also works in other cases.
While researching the problem I came across many similar cases with no clear solution.
The following link has a user with a similar problem (although using ssh and on Ubuntu, rather than local and Fedora in my case).
Thanks in advance!
I spent quite a lot of time trying to figure this problem out, and came across this thread as I found a fix.
My problem was simply that I was running my commands from within the byobu session. I opened a new terminal tab and successfully ran the same commands.
Since DISPLAY is being defined, this may be a problem with permissions. How are you starting X? (As far as I know normally X is started by root and when you login you are granted access such that these issues don't occur, unless you're running sudo from a different account than the one you're logged into X with.)
You need to provide the correct 'cookie' file to access the session (simply being root isn't enough to get in). For users this is normally ~/.Xauthority, so executing xauth merge /home/<user>/.Xauthority should do the trick.
Alternatively have you tried gksu?
I actually needed this (run an X application from CLI with a different user), and valid workarround is to SSH -X:
user1 owns X
user2 is the second user that wants to run an X program from CLI, in this example, eclipse ide
user1:~$ ssh -X user2#localhost
The authenticity of host 'localhost (127.0.0.1)' can't be established.
ECDSA key fingerprint is
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts.
user2#localhost's password:
Welcome to Ubuntu 14.04.1 LTS (GNU/Linux 3.13.0-44-generic x86_64)
user2:~$
user2:~$ /opt/eclipse/eclipse
I know this is 5 years old post, but I spend much time to solve issue like this on installation of Renderman of Pixar. Then I like to send my solution that maybe helps someone else
The problem is because of this "sudoer (here root) has no access to graphical space". (I don't know it is always or sometimes. I faced this issue on Ubuntu 16.04)
Doing the following solved my issue:
first, start Terminal as graphical user, Alt+Ctrl+T
then, execute these lines
$ unset XAUTHORITY
$ xhost add $DISPLAY . 123f
$ xhost +local:all
$ sudo xclock # or any graphical program needs sudoer
Let me know your feedbacks

Error in Cygwin for Moai Android Build

I'm following this tutorial set to set up Moai for Android porting. When I run
./make-host.sh –p com.gamefromscratch.moai
in Cygwin to build the Android host it returns an error of
build.sh: line 17: ndk-build: command not found
I'm 98% certain everything has installed correctly and I've been following the instructions exactly as written. When I look in the shell script line 17 is
use_fmod="false"
I've never had to use shell scripts or set up anything like this before and my scouring of the internet has failed to yield a result.
As a side note, Moai runs perfectly and I haven't had any problems with getting that to work.
I've solved the issue! When I went to look for the environment variable in Windows (Computer -> right click -> properties -> Advanced System Settings -> Environment Variables), I found that the variable path was there but was listed as ‘%PATH;c:\android-ndk’. As an experiment I changed it to just c:\android-ndk and rebooted the computer. I then ran the line to have the host run and it ran through the process without a hitch. The only difference is that instead of untitled-host my file is called host-source and instead of settings-local.sh my file is called d.settings-local.sh. Outside of those minor file name changes everything else is the same.

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