Plink stands for PuTTY Link.
Plink is a companion command-line utility for PuTTY.
A reddit dedicated to the profession of Computer System Administration. PuTTy vs KiTTy (self.sysadmin) submitted 3 years ago by xsoja. What do you guys use/prefer and why? If I'm connecting from a Windows machine or I just use ssh if I'm on a linux box and I'm wanting to connect to one of the few boxes I use with password login.
On a very high-level:
In this tutorial, we’ll discuss the following:
First, download plink executable from here.
If you don’t have PuTTY already installed on your machine, make sure you also download putty executable along with plink.
If you have a 32-bit Windows laptop, make sure you download the 32-bit version of plink. If not, download the 64-bit version.
You can’t just double-click on plink.exe to launch it. Since this is a command-line only utility (Without GUI), you should first launch your Windows command prompt.
For this, click on start menu on your windows, and type “cmd.exe” in the search box and press enter, this will launch the Windows command prompt.
Also, depending on where you have downloaded the plink.exe, you may have to modify the Windows’s PATH variable accordingly.
Go to your “System properties” windows, click on “Environment Variables”, select Path variable, and append the directory where the plink.exe is located here.
Or, you can just set your PATH variable as shown below. In the following example, I’ve downloaded the plink.exe to C:Downloads directory.
Next, type plink in the command prompt, this will display the various options available.
The following is the basic syntax for plink:
In the above syntax:
While the command is optional, when you don’t give it, it will display a raw interactive session, which will have lot of non-printable non-readable character on the screen. As explained earlier, plink is not meant to be used as interactive session. Use putty for interactive session.
For now, let us see various methods to use the connection.
First, you can just give the ip-address of the remote-server. This will then ask for the username and password to login.
Or, you can also use the username using @ symbol as shown below. This will ask only for the password, as we’ve specified the username.
You can also pass the username using -l option as shown below:
You can also use the name of an existing putty session. In this example, I’m using the existing saved putty session called “devdb”. This is the recommended way of using, as you can bring all the configuration information from PuTTY to here for this particular “devdb” session.
The following -load is exactly the same as above.
As you see below, once you login, you’ll get a command-prompt. But, doing anything here will display some non user-friendly characters.
Again, for interactive SSH session, please use PuTTY.
On a related note, even if you’ve been using PuTTY for a while, you might find few tips from here helpful: 10 Awesome PuTTY Tips and Tricks You Probably Didn’t Know
Using plink, from windows, you can execute a command on the Linux server without any user interaction and just display the output.
For this, pass the command as the last argument to the plink as shown below.
In the following example, it will execute “crontab -l” command on the remote server and display the output.
If you want to execute multiple commands, then group them together as shown below.
The following will execute the db-backup.sh shellscript on the remote Linux server. But, you are initiating this from your Windows machine.
Few points to keep in mind:
Instead of specifying all the commands to be executed on the remote Linux server in the plink command-line, you can also put them in a text file and specify the file as a parameter to the plink.
For example, create the following file called commands.txt on your Windows.
Now to execute all of the above commands on the remote Linux server one-by-one in a sequence, execute the following plink command on your Windows laptop.
Plink allows the following protocols: SSH, Telnet, Remote Login (rlogin), Raw, Serial Connection
The most popular and the default is SSH. Use -ssh as shown below.
For Telnet:
For Remote Login using rlogin:
For Raw:
If you are trying to specify a particular protocol, and if you are getting “FATAL ERROR: Network error: Connection refused” error, it means that the remote server doesn’t support the specified protocol.
If you don’t want to specify the protocol on the command line:
If you don’t have the key based authentication setup, then you can pass the password as a parameter in the command-line. Needless to say this method is not recommended.
This will connect to the server as root using the password specified by the -pw option, and execute all the given Linux commands and display the output on your Windows command-prompt.
Of course, the easy method is to use a saved putty session (For example, devdb) instead of specifying the username and ip-address as shown below.
First, make sure you have the latest version of plink. Use -V option (upper-case V) as shown below. The current stable release is 0.69
Next, use -v option (lower-case v) as show below for more verbose output.
By default for SSH, it will connect to port 22. But, on your Linux server if SSH is configured to run on a different port, then use -P option in plink to specify the port.
In the following example, plink will connect to the remote Linux server on port 25.
When you use a saved PuTTY session and -P option, instead of using the port from the saved session, it will use the given Port.
For the SSH protocol in Plink, there are couple of useful logging options.
The following –sshlog option will save the logs in the given file (sshlog.txt).
This is the partial content of the sshlog.txt output
For more detailed log, use -sshrawlog option. Please note that the filesize of this will be larger than the above, as this will store lot more information in the log file.
Also, this will take longer to execute than the above command, as sshrawlog option collects more log information than regular sshlog option.
By default, it will use SSH-2 protocol, which can also be specified using -2 option as shown below.
For SSH-1 protocol, use -1 option as shown below. If your server doesn’t support it, you’ll get the following error.
By default, it will use IPv4, which can also be specified using -4 option as shown below.
To use IPv6, use-6 option as shown below.
Use -i option to specify the location of the private key file that should be used for authentication.
In the following example, it will use the devdb.ppk file from C:Downloads directory.
Note: You’ll get “Server refused our key”, if the given key is not properly configured to be used with your Linux Server.
If the key file is not found (for example, when you give a wrong directory name), you’ll get the following error:
If you specify a Key what is not of proper format, you’ll get the following error message.
You can also use the following plink SSH options:
Use -pgpfp option which will display the PGP fingerprint details for PuTTY. Typically you can use this to establish trust from plink.exe executable to another program or executable that you are trying to connect to.
Also, you can use hostkey in the plink to connect to the remote server accordingly using -hostkey option.
If you are running plink inside a Windows batch file, then it is recommended that you use -batch option.
In the above example, if the complex-linux-command fails, or asking for an input from the user, or hangs, etc, then your Windows Batch script will not be waiting. Instead, plink will just abandon the command, and the batch script will fail.
This is probably what you would expect to happen instead of your windows batch file job just waiting or hanging.
So, use -batch option in plink when you are writing Windows batch scripts using plink.
I am unable to connect to ubuntu linux on windows putty machine.I have taken ip from ifconfig and I am trying to login via putty using the same ip.I am getting network refused warning.Can anyone please help me how to resolve the issue.
ThomasInstall the openssh-server
package on Ubuntu :
Or:
Check the status of the service :
or
or
To start the service just replace status
with start
on the above commands
Allowing the port 22
through ufw
: