Wednesday, April 24, 2013

Running programs on server using Screens command

In my last blog I have discussed a way of connecting to your server PC at home from anywhere over the internet either on another desktop or on mobile device. I faced a problem of getting disconnected from the server when the phone signals were week on the move. So tasks like compiling of android source code was halted as soon as I get disconnected from the ssh client. Here is a way to overcome this problem which i found on the internet:

Login to the server using the ssh client and start a screen on the server. Now the shell will actually be running on the server rather than the client.
$ screen
Any other ssh client can now get connected to this screen and can view a copy the screen on their local shell. Even if the client gets disconnected due to any reason, the shell will still be running on the server.

To display the screens running on server:

jaiprakash@jaiprakash-Inspiron-1525:~$ screen -ls

There are screens on:

    2941.pts-4.jaiprakash-Inspiron-1525    (Wednesday 24 April 2013 11:15:52  IST)    (Attached)

    2811.pts-0.jaiprakash-Inspiron-1525    (Wednesday 24 April 2013 11:14:33  IST)    (Attached)

2 Sockets in /var/run/screen/S-jaiprakash.

To connect to a particular screen:
$ screen -x 2941.pts-4.jaiprakash-Inspiron-1525        --> to get a copy of the screen i.e. the shell running on the server.

if only one screen is running the simply use the command
$ screen -x

To disconnect from the screen (but process should be running on the server, in other words only to disconnect the client) use ctrl+A and ctrl+D or ctrl+A and type :detach
You would now be disconnected from the screen. but the process would still be running on the server.

I found it very useful for myself while using the ssh over internet. The screen command is very useful when the client gets disconnected abruptly. Hope this helps to remote developers :-P.

Reference: http://www.howtogeek.com/howto/ubuntu/keep-your-ssh-session-running-when-you-disconnect/

Sunday, April 21, 2013

Accessing my computer from anywhere over internet using ssh and port forwarding

1. Creating a free account on noip.com
Create an account on noip.com. You'll receive a confirmation mail from noip.com. Confirm the link.

Login to your account on noip.com and goto
My Account > Hosts/Redirects > Manage Hosts > Add a host
Chose a proper host name (ex: myserver) and a free domain (ex: zapto.org) from the available list and click on "Update host" when completed.

2. Installing the noip client on device to be accessed
Now Download the noip2 tool from the site under Hosts/Redirects > Download Client

Unzip the noip-duc-linux.tar.gz and install it
$ tar -xzvf noip-duc-linux.tar.gz
$ cd noip-2.1.9-1
$ sudo make install
$ sudo noip2 -C
[sudo] password for user: 

Auto configuration for Linux client of no-ip.com.

Please enter the login/email string for no-ip.com youremail@gmail.com
Please enter the password for user 'youremail@gmail.com'  ********

2 hosts are registered to this account.
Do you wish to have them all updated?[N] (y/N)  n
Do you wish to have host [myserver.no-ip.biz] updated?[N] (y/N)  n
Do you wish to have host [myserver.zapto.org] updated?[N] (y/N)  y
Please enter an update interval:[30]  
Do you wish to run something at successful update?[N] (y/N)  n

New configuration file '/usr/local/etc/no-ip2.conf' created.

To check the status:
 $ sudo noip2 -S

No noip2 processes active.
 
Configuration data from /usr/local/etc/no-ip2.conf.
Account youremail@gmail.com
configured for:
    host  myserver.zapto.org
Updating every 30 minutes via /dev/wlan0 with NAT enabled.

3. Port Forwarding of local wifi network to be accessible from anywhere over internet
Now we need to give access to wifi router to access ssh port from anywhere in the internet. I followed the tutorial from this site and it worked well for me. For my beetel wifi router on airtel network on the browser, login to wifi http://192.168.1.1
user: admin
password: password
http://portforward.com/english/routers/port_forwarding/Beetel/450TC1/defaultguide.htm

4. Changing default ssh port
So we are almost done now. However its recommended to change the ssh port from default (default port 22) settings while forwarding it to internet for security reasons.

To change the ssh port:
sudo vi /etc/ssh/sshd_config and change the following line to custom port address

 ListenAddress 0.0.0.0:44812 

--> make sure that this port number matches the port address described in the portforward.com tutorial.

Also you can make your device ip static. For Raspberry pi, i have mentioned the modifications in the comments of previous post.

5. Accessing over internet using ssh client
Now, to access the device from anywhere from the internet. I am using the ConnectBot client in Android to access my device remotely.

 ssh username@myserver.zapto.org:44812

--> you should be connected to your device now. Cheers, now I can access my device from anywhere using my android phone :-).

Friday, March 15, 2013

Setting up wifi on Raspberry Pi

I recently bought a "NETGEAR wifi dongle" fo my Raspberry Pi so free it from the wired ethernet connections. The details of the wifi dongle is as follows:
$lsusb
Bus 001 Device 004: ID 0846:9041 NetGear, Inc. WNA1000M 802.11bgn [Realtek RTL8188CUS]

To configure it to the local wifi network:

modify /etc/network/interfaces as follows
For example if my wifi network's name is "~Jaguar~" and password is "Password123"
auto lo

iface lo inet loopback
iface eth0 inet dhcp
allow-hotplug wlan0
auto wlan0
iface wlan0 inet dhcp
        wpa-ssid "~Jaguar~"
        wpa-psk "Password123"

Softreboot the system and wifi should be working.
$ sudo shutdown "now" -r

To re-confirm
pi@raspberrypi ~ $ ifconfig
eth0      Link encap:Ethernet  HWaddr b8:27:eb:ae:b2:aa  
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:95 errors:0 dropped:0 overruns:0 frame:0
          TX packets:84 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:9356 (9.1 KiB)  TX bytes:13962 (13.6 KiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:6402 errors:0 dropped:0 overruns:0 frame:0
          TX packets:6402 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:19282157 (18.3 MiB)  TX bytes:19282157 (18.3 MiB)

wlan0     Link encap:Ethernet  HWaddr 84:1b:5e:92:bf:e8  
          inet addr:192.168.1.8  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2182 errors:0 dropped:2359 overruns:0 frame:0
          TX packets:2001 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:289214 (282.4 KiB)  TX bytes:1055742 (1.0 MiB)
and
 pi@raspberrypi ~ $ iwconfig  
lo        no wireless extensions. 
 
wlan0     IEEE 802.11bg  ESSID:"~Jaguar~"  Nickname:"<WIFI@REALTEK>"
          Mode:Managed  Frequency:2.412 GHz  Access Point: 80:A1:D7:8D:A3:24   
          Bit Rate:54 Mb/s   Sensitivity:0/0  
          Retry:off   RTS thr:off   Fragment thr:off
          Power Management:off
          Link Quality=100/100  Signal level=100/100  Noise level=0/100
          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
          Tx excessive retries:0  Invalid misc:0   Missed beacon:0  
 
eth0      no wireless extensions.  
For Internet to work: use
$ sudo /sbin/route add -net 0.0.0.0 -gw 192.168.1.1 wlan0
where 192.168.1.1 is gateway of my router.

Hope this post helps. :-)

Saturday, March 9, 2013

Remote Desktop of Raspberry Pi onto Ubuntu/Android/Windows

I recently bought a Raspberry Pi board from crazypi.com. Raspberry is a low cost chipset from Broadcom which can host linux and many other OS. It just costs 3K INR if you buy it in India. It is an awesome lowcost chipset with 2 USB ports, one ethernet port, one HDMI port, one TV out and one audio jack port. It also has a micro-USB power input and SD card, from where the OS boots.

Now I am gonna explain how to setup remote desktop from Raspberry Pi to Linux or Windows PC. VNC and RDP protocols are famous for desktop sharing. Both have their advantages and disadvantages. However I prefer RDP over VNC, because VNC often gets stuck while using Desktop sharing. I am gonna explain setting up of both the protocols on Raspberry Pi:

1. Using VNC protocol

Server Configurations on Raspberry Pi:
- Install tightvncserver on the Raspberry
$ sudo apt-get install tightvncserver

- Enter passwords if prompted.

- start the vncserver with the following command

$ vncserver :1 -geometry 800x600 -depth 32 -pixelformat rgb565
   
- Now you are ready to connect to Raspberry Pi remotely from any VNC client either on Ubuntu or Android.

Client Configurations:
On Ubuntu: install vncviewer, to connect remotely, install necesarry packages when prompted.

$ vncviewer 192.168.1.3:5901

   

On Android: Download VNC client app from Android market. I downloaded "androidVNC" app from market, works well on my Galaxy Nexus.

Nickname: raspberry:1

password: <type in the view password set while installing vncserver on Raspberry Pi>

Address: <enter ip address of RPi; ex: 192.168.1.3>

Port: 5901


- To kill the server
$ vncserver -kill :1

However I was unable to browse comfortable using VNC so I decided to use RDP protocol. RDP is faster and preferred over VNC and it performs better.

2. Using RDP protocol
Server Configurations on Raspberry Pi:
- Install the xrdp package on Raspberry Pi

$ sudo apt -get install xrdp

- Thats it, the server is ready on RPi. Restart if required.

Client Configurations:
On Ubuntu: Applications > internet > Terminal server Client

Computer: 192.168.1.3
Protocol: RDPv5
User name: pi
Password: raspberry

Alternatively you can use the rdesktop command from the shell as follows:
$ rdesktop -u pi -p raspberry 192.168.1.3 




On Android: Install a RDP client, I used "AccessToGo Remote Desktop/RDP" and "Ahope RDP Client"from Android market. plugin the details as required.




This is really coooooooooool.

Using Rapberry Pi Command Prompt on other devices:
In addition, to access Raspberry Pi in command shell
On ubuntu: 

$ ssh pi@192.168.1.3 

On android: Download "ConnectBot" app from the Android market. Plugin the details and you are ready to go. :-)

You can expect some more stuff on Raspberry Pi sooner.

See you...