Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In windows we have created a batch file to login into a machine via putty. On clicking the batch file it logins into that machine. Is it possible to create a script in ubuntu to do the same task?

share|improve this question
up vote 5 down vote accepted

Create a launcher server.desktop with the following content:

[Desktop Entry]
Name=Server Name

and give it execution permissions.

Obviously you should put the real user and the real in the Exec= line.

To allow to choose the username, substitute the Exec= line with the following:

Exec=sh -c 'user=$(zenity --entry --title="Set username" --text="Username: " --entry-text="$USER"); if [ -n "$user" ]; then ssh $; else exit; fi'
share|improve this answer
What i want is, On clicking the script it should login into the machine. – karthick87 May 30 '11 at 14:32
karthick87: without entering a password? You'll need to use key-based authentication for that. Pass the -i option to ssh with the next argument the path to the private keyfile. – Lekensteyn May 30 '11 at 14:41

Following up enzotib's answer: if you hardcode the login information in every script and file, it will make it more difficult to change it later if needed. A better solution would be creating a SSH configuration file with settings grouped under a host alias.

Instead or running:

ssh -p 1234 -i ~/.ssh/id_rsa

you can create a ~/.ssh/config file containing:

Host meh
    User admin
    Port 1234
    IdentityFile ~/.ssh/id_rsa

Each of the settings below meh are optional, and when omitted, it will use defaults.

The command would then be:

ssh meh

You're allowed to override settings, the below command would login with username super using the keyfile ~/.ssh/other_key and (provided by the config file) hostname on port 1234:

ssh super@meh -i ~/.ssh/other_key
share|improve this answer
+1, I too use config file, but opted for a quick solution in the answer. – enzotib May 30 '11 at 15:16

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.