Connect To VNC Server Without Typing Password
Remoting into a server can be very useful, whether it be to work from home or simply to use a headless machine. In my case I am using TightVNC to connect to a Windows machine right next to my Arch Linux box because I need Windows now and then for certain tasks because I work in a primarily Windows office. I could run a VM on my linux box but that would put an extra load on my system. I could also dual boot for my Windows needs, but this is a big time sink. Ultimately I have chosen to run Windows on a separate machine to keep both environments running smoothly. Now this setup is not ideal because the Windows box is fairly weak, Intel Core2 6600 with 2GB ram, so when the system is under heavy load the VNC viewer tends to lag a bit.
To set up the VNC viewer to fit into my workflow I wanted a way to open it without having to open terminal to run the command every time, or at the very least have a shorter command to type. There are two ways to reach this solution: create a menu entry in Openbox and create a permanent bash alias. But first we must create a password file so that we can login without typing the password. To do this we need to use vncpasswd.
Create passwd file:
First, start vncpassword by running:
$ vncpasswd
Using password file /home/user/.vnc/passwd
Password:
Verify:
Would you like to enter a view-only password (y/n)? n
The default behavior is to save the file to the .vnc/ folder unless the -t option is used. Click here to read the vncpasswd man pages to learn more. Enter your password when prompted. If you would like to enter a view-only password respond accordingly for your specific setup. In my case I did not want to set up a view-only password.
Now that you have your passwd file you can use it to connect to your VNC server. In my case I renamed the passwd file to the hostname of my remote machine (margaery) so that I could setup a passwd file for each remote server I wanted to connect to. Here is the command I now use to connect to my remote VNC server:
$ vncviewer -passwd ~/.vnc/margaery 192.168.1.100
Make sure to use the correct IP that corresponds to your machine. In this case I used a local IP because I do not intend to connect from outside the local network.
Openbox menu entry:
Now that we have the passwd file configured properly we need to create a menu entry in Openbox. Start by opening /home/user/.config/openbox/menu.xml in a text editor.
Add a new app menu item before the root menu at the end. Mine looked something like this:
<span class="code">
<menu id="apps-vnc-menu" label="VNC">
<item label="Margaery">
<action name="Execute">
<command>vncviewer -passwd ~/.vnc/margaery 192.168.1.100</command>
</action>
</item>
</menu>
</span>
We then need to add the new menu we just created to the applications portion of the root menu:
<span class="code">
<menu id="root-menu" label="Openbox 3">
<menu id="apps-vnc-menu"/>
</menu>
</span>
I have many other entries in the menu but I omitted them for brevity. Save your changes and close the editor. Note that your changes will not take effect until you restart Openbox.
Bash Alias:
Another option is to set up an alias in your .bashrc. To do this open ~/.bashrc in a text editor. Add a line to the bottom similar to the following:
alias vncmargaery="vncviewer -passwd ~/.vnc/margaery 192.168.1.100"
Replace vncmargaery with whatever you want the new alias to be, i.e., what you type into terminal to connect to your VNC server. Just be sure to not enter in a command that already exists. Next enter the command you used from before to connect to your VNC server. This means you will likely need to change the passwd file path and the IP address from the example above. Note that you will need to restart your terminal for the changes to take effect so that you can use the alias.
Well there you have it. We can now connect to a VNC server by either finding it in our openbox menu or by typing the alias into our terminal. I hope this was helpful, and if it was feel free to let me know on twitter or facebook so I know to keep writing this kind of stuff.
Vi ses!