1

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?

karthick87
  • 84,513

2 Answers2

5

Create a launcher server.desktop with the following content:

[Desktop Entry]
Name=Server Name
Exec=ssh user@server.domain.com
Terminal=true
Type=Application

and give it execution permissions.

Obviously you should put the real user and the real server.domain.com 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 $user@server.domain.com; else exit; fi'
enzotib
  • 96,093
4

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 admin@meh.example.com -p 1234 -i ~/.ssh/id_rsa

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

Host meh
    HostName meh.example.com
    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 meh.example.com on port 1234:

ssh super@meh -i ~/.ssh/other_key
Lekensteyn
  • 178,446