Saturday, February 20, 2010

Working on remote linux server

Logging into remote linux server:
$ ssh username@remoteserver.com
Now enter your password and voila :D. Probably you know this. Just warming up a bit.

» What if ssh server is opened at a different port other than default 22?
If you server opened ssh in a different port, you can use this.
$ ssh -p 9009 username@remoteserver.com

» Want to transfer a war file to remote server?
$ scp demo.war username@remoteserver:/opt/apache/tomcat/webapps/
Or copying log files back to your machine?
$ scp -r username@remoteserver:/opt/apache/tomcat/logs /home/myself/

» You may not want to use password every time you log into the server.
You can create public-private key pair on you machine and share the public key with the remote server for ssh to use it.
Create key pair on your machine:
$ ssh-keygen -f ~/.ssh/id_fun
You'll find two files in ~/.ssh folder id_fun and id_fun.pub which are the private and public key respectively.
share id_fun.pub with the remote server and add to ~/.ssh/authorized_keys files
$ scp ~/.ssh/id_fun.pub username@remoteserver:/home/username/.ssh/
$ ssh username@remoteserver
# you need to enter password now
username@remoteserver$ cat ~/.ssh/id_fun.pub >> authorized_keys


Go back to you machine and try 'ssh username@remoteserver' and log into remote server without any password.
Do i have to tell you that you don't share id_fun with any one.

» Didn't like scp'ing. Why not mounting remote server's file system to yours?
$ mkdir /mnt/serverishere
$ sshfs
username@remoteserver:/home/username/eveything /mnt/serverishere
Now you can find everything folder is mounted to /mnt/serverishere on you machine.

No comments: