Thursday, November 25, 2010

Configure SSH to connect to a server without username/password

If you are bored having to enter your username and password everytime you connect to a server you can do the following

In your pc run "ssh-keygen"

This will generate public/private rsa key pair.

Then run "ssh-copy-id username@servername"

This will copy the appropriate files to the remote server

Now you can connect to the server and you will not be asked for your credentials.

You can also add the following lines to your ~/.ssh/config file

Host servername
 User username
 Port 2222


This will always connect you to the servername using username at port 2222

Thursday, October 14, 2010

Connect to a port of a remote server through SSH (local port forwarding)

This is the scenario

You want to connect to a remote server's webserver (port 80), but you only have permission to SSH to that server. Do the following:

ssh -L 8080:localhost:80 remote_server

Now you can point your browser to hhtp://localhost:8080 and view remote server's port 80

localhost is relevant to the remote_server

Also, you can do

ssh -L 8080:remote_server_2:80 remote_server_1

Now if you point your browser to http://localhost:8080 you will connect remote_server_2 port 80. The connection will go through remote_server_1 and remote_server_2 will identify remote_server_1 as the source of the request.

This way you can view a web server of a system even though you cannot connect to it directly. Of course remote_server_1 must be able to connect to remote_server_2 at port 80.

You can also use Putty to enable port forwarding. Go to Connection-->SSh-->Tunnels and set the required options.

Display remote X applications to your desktop

The easiest thing you can do is to SSH to the remote server activating the X11 forwarding.

ssh -X remote_server

From now on anything you execute on the remote server appears on your desktop

SOCKS proxy with SSH

From your PC give

ssh -D XXXX Proxy_GW_IP

To your browser or any client that supports SOCKS set Proxy_GW_IP as your proxy server and use port XXXX.

Now you can browse the internet as if you were the Proxy_GW

Tuesday, June 22, 2010

Synchronize windows & linux folders using samba and rsync

I've been trying all night long to synchronize two folders. The source was a shared Windows NTFS partition and the destination a local folder on Ubuntu. After numerous re-tries did it.

First I had to mount the NTFS partition


sudo smbmount //REMOTE_IP_ADDRESS/SHARED_FOLDER /LOCAL_FOLDER -o username=REMOTE_USER,password=REMOTE_USER_PASSWORD,iocharset=utf8,file_mode=0777,dir_mode=0777

Afterwards I run rsync as if the two folders were local. There is also a handy GUI version for rsync, grsync.

When you finish don't forget to unmount it

sudo smbumount /LOCAL_FOLDER