Putty and related tools (pscp, psftp, plink)

Source: Internet
Author: User
Tags tmp folder filezilla pscp secure copy ssh port putty sftp
Document directory
  • Use of pscp
  • Let's take a look at psftp.
  • Other optional sftp clients

 

With the popularization of Linux applications on servers, Linux system management is increasingly dependent on remote management. Putty is one of the excellent remote logon tools.

Putty is a free telnet, rlogin, and SSH client on Windows 32, but its functions are not inferior to commercial Telnet tools. It is very easy to use to remotely manage Linux. Its main advantages are as follows:

◆ Completely free
◆ Windows 9x/NT/2000 run very well
◆ Full support for SSH1 and SSH2
◆ The green software does not need to be installed. After downloading it, create a shortcut on the desktop to use it.
◆ Small size, only 0.54 KB (Beta)
◆ Simple operation, all operations are implemented in a control panel

Introduction:
Download puttyto the machine and double-click putty.exe. The configuration interface of 1 is displayed. Select "session" and enter the host name or IP address to be accessed in the "host name (or IP address)" input box, for example, server1 or 192.168.9.4. Port is different based on the protocol used. SSH uses 22 by default, telnet uses 23 by default, and rlogin uses 513 by default. Select the protocol used in the "protocol" Radio Bar, usually telnet or SSH, depending on the service provided by the server. In the "saved session" input column, enter the Task Name and click the "save" button to save the task configuration.

After the configuration is complete, click the "open" button. On the logon page 2 displayed, you can use Putty to connect to the Linux host.

FAQs about putty

1. When you use putty in Windows to log on to FreeBSD, you can enter the user name. However, after you enter the password, press the Enter key for half a day.

A: The configuration process is as follows:
1. Add the following content to/etc/ssh/sshd_config so that common users can log on via SSH:

Allowusers Common User Account

Usedns No

2. Add the user who wants to use the su command to the wheel group and make the following changes in/etc/group:

Wheel: *: 0: Root, common user account

2. Enter the user name after login as:, J04222035@cs8.xmu.edu.cn's password: The cursor does not move. No response even if you enter the correct password?

A: This is because putty does not directly display the password as Telent does. As long as you enter the correct password, even if it is not displayed, you only need to press enter after entering the password, don't care if the cursor does not move.

Finally, it's the pagent's turn. Double-click pagent.exe. Well, no response? Double-click it again. Why? A prompt is displayed, indicating that the task is running.

Let's look at the bottom right corner.

Double-click the pagent icon to display this interface. The add key is a private key, and the remove key is used to detach the selected private key from the pagent.

Now, click Add key to add the private key. I saved the private key used for this demonstration to C :/.

The enter key Password dialog box appears. Enter the correct key and click OK.

Then, in the pagent window, we can see that our private key has been mounted.

Open putty, select the previously saved session, and double-click it. As long as the username is set to be automatically logged on, the authorized_keys file of the account on the host also contains the matching public key. Haha, no? No Password is required. We have logged on to the system.
Right-click the pagent icon, or you can quickly select a saved session.

We recommend that you put pagent in the startup group so that pagent runs automatically every time the machine is started, and then we only need to load the private key, then we can continue to enjoy the fun of automatically logging on to the system. With the plink and pscp mentioned later, we can automate a lot of work. There is no need to input usernames, passwords, long and many commands each time, and then back up some annoying files. At last, remember to log out of the system. Isn't it troublesome? All these troubles will soon be far away from us. Let's continue.

Use SSH to transfer files

Putty provides two file transfer tools

  • Pscp (putty secure copy client)
  • Psftp (putty SFTP client)

Pscp is connected through SSH and securely transfers files between two machines. It can be used on any SSH (including SSH V1 and SSH v2) server.
Psftp is a new feature in the SSH-2, using the new SFTP protocol, using a similar to the traditional FTP. In fact, if SFTP is found to be available, pscp will use SFTP protocol to transmit files; otherwise, it will still be SCP protocol. Compared with pscp, psftp can interact with the server, traverse the file system on the server, and upload or download multiple files in one session. Pscp can only transmit one file at a time, and terminate the session immediately after the transfer is completed.

Use of pscp

Run pscp directly on the console to see help

C:/> pscp
Putty secure copy client
VPC: Release 0.58
Usage: pscp [Options] [user @] HOST: Source Target
Pscp [Options] source [source...] [user @] HOST: Target
Pscp [Options]-ls [user @] HOST: filespec
Options:
-V print version information and exit
-Pgpfp print PGP key fingerprints and exit
-P preserve file attributes
-Q quiet, don't show statistics
-R copy directories recursively
-V show verbose messages
-Load sessname load settings from saved session
-P port connect to specified port
-L user connect with specified Username
-PW passw login with specified password
-1-2 force use of particle SSH protocol version
-4-6 force use of IPv4 or IPv6
-C enable Compression
-I key private key file for authentication
-Batch disable all interactive prompts
-Unsafe Allow server-side wildcards (dangerous)
-SFTP force use of SFTP protocol
-SCP force use of SCP Protocol

C:/>

It can be seen that the use of pscp is very simple. Let's talk about several common options:

  • -Q quiet mode: When a file is transmitted, nothing is displayed. Otherwise, the file transmission progress is displayed. The default setting is disabled.
  • -P port specifies the ssh port of the server. Note that this is the uppercase letter P. The default value is-P 22. If the ssh port of the host is 22, you do not need to specify it.
  • -L User specifies the user identity to log on to the host. If not, pscp obtains the Default User name in the session with the same name saved by putty. User Names can also be written together with host names and separated by @, for example, username @ Server
  • -PW passwd: Specify the password used for Logon As passwd.
  • -I Keyfile is the key file used for logon.
  • The host name specified at the end can also be the session name saved in putty. For example, we saved a session named foobarserver in putty, and our network does not have a host name named foobarserver. The host name saved in this foobarserver session is demo-server, and the saved Automatic Login User is Taylor. Use commands
    Pscp C:/autoexec. Bat foobarserver: backup/

    Copy the local C:/autoexec. BAT file to the backup subdirectory in the main directory of user Taylor on the demo-server of the host (this path may be/home/Taylor/backup

The general usage of pscp is as follows:
Pscp-P 22-I c:/path/your-private-key.ppk-C username @ server:/remote/path/
It is easier to use some instances as follows:
Copy the local C:/path/foo.txt file to the/tmp directory of the remote host 192.168.6.200

Pscp C:/path/foo.txt 192.168.6.200:/tmp

Copy the local C:/path/foo.txt file to the/tmp directory of host 192.168.6.200, but execute it with Taylor's permission on host.

Pscp C:/path/foo.txt taylor@192.168.6.200:/tmp

Or

Pscp-l Taylor C:/path/foo.txt 192.168.6.200:/tmp

Transfer the local C:/path/foo.txt file to the/tmp directory of host 192.168.6.200, but the host's SSH port is 3122.

Pscp-P 3122 C:/path/foo.txt 192.168.6.200:/tmp

Copy the local C:/path/foo.txt file to the main directory of user Taylor at host 192.168.6.200.

Pscp C:/path/foo.txt taylor@192.168.6.200 :.

Copy all *. tgz files under user Taylor's home directory on host 192.168.6.200 to the local C:/backup directory. If the SSH version is SSH V1, this command will cause an error.

Pscp taylor@192.168.6.200: *. tgz C:/backup

Let's take a look at psftp.

Run the command psftp-H on the console to get help from psftp.

C:/> psftp-H
Putty Secure File Transfer (SFTP) Client
VPC: Release 0.58
Usage: psftp [Options] [user @] Host
Options:
-V print version information and exit
-Pgpfp print PGP key fingerprints and exit
-B file use specified batchfile
-BC output batchfile commands
-Be don't stop batchfile processing if errors
-V show verbose messages
-Load sessname load settings from saved session
-L user connect with specified Username
-P port connect to specified port
-PW passw login with specified password
-1-2 force use of particle SSH protocol version
-4-6 force use of IPv4 or IPv6
-C enable Compression
-I key private key file for authentication
-Batch disable all interactive prompts

C:/>

The usage is similar to that of pscp. Although there is a-load option, it is useless. When the host name is used later, you can directly use the session name like pscp.
After logging on to the server using psftp, the operation is similar to that of FTP. Here is a simple introduction:

  • Open login host
    Open [username @] <sessname | hostname | ip> [port]
    For example:

    • Open Taylor @ demo-server 3022
      Log on to the demo-server host as user Taylor. The ssh port is 3022.
    • Open demo-Server
      Log on to the demo-server. Here, the demo-server can be the saved session name in putty or the host name. If the host name is the same as the session name, the session name prevails.
  • Close to close SFTP connection
    Close closes the SFTP connection.
  • Quit ends this SFTP session
    No usage, that is, the psftp program is closed.
  • Help [command] Help
    You can directly call help to view the HELP command. You can specify the previous command to view the help of the command, for example: help open
  • CD [Directory] changes the current directory
  • PWD: view the current directory
  • LCD [Directory] Change local directory
  • Lpwd: Check the local directory
  • Get [-R] <FILENAME | directory> downloads a file/directory from the server. This command cannot use wildcards. The parameter-R can recursively download the entire directory.
  • Put [-R] <FILENAME | directory> [DEST] uploads files/directories to the server. This command cannot use wildcards. The parameter-R can recursively upload the entire directory.
  • Mget [-R] <FILENAME | directory> downloads a batch of files/directories from the server. Wildcards can be used. The meaning of-r is the same as that of get.
  • Mget [-R] <FILENAME | directory> [DEST] uploads a batch of files/directories to the server. Wildcards can be used. The meaning of-r is the same as that of put.
  • Reget [-R] <FILENAME | directory> downloads a file/directory from the server. This command cannot use wildcards. The meaning of-r is the same as that of get.
  • Reput [-R] <FILENAME | directory> [DEST] uploads a batch of files/directories to the server. This command cannot use wildcards. The meaning of-r is the same as that of put.
  • Dir [Directory] column directory
  • Ls is the same as dir.
  • Chmod changes the file permission, which is similar to the CHMOD command of UNIX.
  • Del <FILENAME> delete an object. Note that del can only delete objects.
  • Rm is the same as Del.
  • Mkdir <New-directory-Name> creates a directory.
  • Rmdir <directory> deletes an empty directory. Only the empty directory can be deleted.
  • MV <source-file | source-directory> <DEST-file | DEST-directory> is renamed/moved. If both the source and target are files or directories, change the name. If the target is a directory, it is moved.
  • ! Add an exclamation point before the local command to directly execute

 

Other optional sftp clients

Filezilla: http://filezilla.sf.net
Winscp: http://www.winscp.net

Execute commands on the remote host more conveniently and quickly with plink

Plink is a putty Command Line Connection Tool, mainly used for automated processing.
Run plink directly on the console. You can see the help of plink.

C:/> plink
Putty link: command-line connection Utility
VPC: Release 0.58
Usage: plink [Options] [user @] host [command]
("Host" can also be a putty saved session name)
Options:
-V print version information and exit
-Pgpfp print PGP key fingerprints and exit
-V show verbose messages
-Load sessname load settings from saved session
-Ssh-Telnet-rlogin-raw
Force use of a particle Protocol
-P port connect to specified port
-L user connect with specified Username
-Batch disable all interactive prompts
The following options only apply to SSH connections:
-PW passw login with specified password
-D [Listen-IP:] Listen-Port
Dynamic socks-based port forwarding
-L [Listen-IP:] Listen-Port: Host: Port
Forward local port to remote address
-R [Listen-IP:] Listen-Port: Host: Port
Forward remote port to local address
-X-x enable/disable X11 forwarding
-A-a enable/disable agent forwarding
-T-t enable/disable Pty allocation
-1-2 force use of particle Protocol version
-4-6 force use of IPv4 or IPv6
-C enable Compression
-I key private key file for authentication
-M file read Remote Command (s) from File
-S remote command is an SSH subsystem (SSH-2 only)
-N don't start a shell/command (SSH-2 only)

C:/>

It seems that plink's usage and parameters are similar to pscp and psftp.

  • -P port specifies the ssh port of the server. Note that this is the uppercase letter P. The default value is-P 22. If the ssh port of the host is 22, you do not need to specify it.
  • -L User specifies the user identity to log on to the host. If not, pscp obtains the Default User name in the session with the same name saved by putty. User Names can also be written together with host names and separated by @, for example, username @ Server
  • -PW passwd: Specify the password used for Logon As passwd.
  • -I Keyfile is the key file used for logon.
  • -M file: if many commands are executed, you can write the commands to the file and use this parameter to specify

Let's use some practical examples to illustrate plink.
Do you still remember the configuration that mentioned Putty's automatic command execution? When talking about the configuration, we demonstrated a simple Tomcat restart command, which should be written in the remote command of putty. Now we use plink to implement the same function:
Assume that the connected host is 192.168.6.200 and the ssh port is 3022. the user is Taylor:

Plink-P 3022 taylor@192.168.6.200 export catalina_home = "~ /Apache-Tomcat-5.5.17 "; export java_home = "~ /Jdk1.5.0 _ 07 "; export Path = $ java_home/bin; $ path; CD $ catalina_home/bin ;. /shutdown. SH ;. /startup. SH; tail-F $ catalina_home/logs/Catalina. out

If a session named 192.168.6.200 is saved in putty, note that the session name is the same as the host IP address, and port 3022 has been properly saved in the session, if the default user is Taylor, this command can be simplified:

Plink 192.168.6.200 export catalina_home = "~ /Apache-Tomcat-5.5.17 "; export java_home = "~ /Jdk1.5.0 _ 07 "; export Path = $ java_home/bin; $ path; CD $ catalina_home/bin ;. /shutdown. SH ;. /startup. SH; tail-F $ catalina_home/logs/Catalina. out

Run the date command to view the time on the host and format the output:

Plink 192.168.6.200 date "+ % F % t"

When you actually execute the command, you will find that this command does not return the expected result, but returns an error:

C:/> plink 192.168.6.200 date "+ % F % t"
Date: Too required non-option arguments: % t
Try 'date -- help' for more information.

However, if the date "+ % F % t" command is directly executed on the server, it is indeed correct. What's wrong? This is because the windows console will pass the string between two double quotation marks as a parameter to the program to be executed, rather than the double quotation marks to the program. Let's make a small experiment to illustrate this problem:
For example, in the C:/tmp folder, create three folders named "foo", "bar", and "foo bar ". Create a folder named "foo. log, create a file named bar in the bar folder. empty file of log, create an empty file named foo-bar.log in the folder "foo bar.
Go to the C:/tmp folder on the console and run the following command:

Dir Foo bar

The result is to list the content in the "foo bar" folder, or to list the content in the "foo" and "bar" Folders respectively? The correct answer is the latter.
To correctly list the items in the "foo bar" folder, use double quotation marks to enclose "foo bar ".

C:/tmp> dir Foo bar
Volume in drive C is System
Volume serial number is 9c51-a51c

Directory of C:/tmp/foo

<Dir>.
<Dir> ..
0 Foo. Log
1 file (s) 0 bytes

Directory of C:/tmp/Bar

<Dir>.
<Dir> ..
0 bar. Log
1 file (s) 0 bytes
2 Dir (s) 1,107,345,408 bytes free

C:/tmp> dir "foo bar"
Volume in drive C is System
Volume serial number is 9c51-a51c

Directory of C:/tmp/Foo bar

<Dir>.
<Dir> ..
Foo-bar.log
1 file (s) 0 bytes
2 Dir (s) 1,107,345,408 bytes free

C:/tmp>

Speaking of this, we will understand that the above command plink 192.168.6.200 date "+ % F % t" actually executed on the host is date + % F % t, instead of the date "+ % F % t" specified in the command line ". But fortunately, the Windows Console does not recognize single quotes, so the correct usage of the above command should be:

C:/> plink 192.168.6.200 date '+ % F % t'
2006-11-22 09:39:57

I often need to log on to the server to re-dial ADSL, you can write the following command to a text file, such as Save to C:/adsl-restart.command.txt

Echo "stoping ..."
/Sbin/ADSL-stop
Echo "starting ..."
/Sbin/ADSL-start
Echo "done ."
/Sbin/ADSL-status

Run the following command:

Plink-m c:/adsl-restart.command.txt root@192.168.6.251

I often want to view Tomcat running logs

Plink taylor@192.168.6.200 tail-f ~ /Apache-Tomcat-5.5.17/logs/Catalina. Out

Use this command to view the remaining space on the server every day:

Plink taylor@192.168.6.200 (DF-K)

Assume that www.chaifeng.com is connected to another network segment 10.204.26.0 and a Solaris 8 host with an intranet IP address of 10.204.26.21 can only log on via Telnet. To prevent listening, we can use plink to establish a tunnel, the tunnel is open for 120 seconds. If the tunnel is not used, the connection is automatically disconnected. Then, you can run the Telnet localhost 2623 command locally to log on to the Solaris 8 host safely.

Plink-l 2623: 10.204.26.21: 23 www.chaifeng.com sleep 120

A Tor is running on the host www.chaifeng.com. The default listening address is 127.0.0.1: 9050. Use plink to create a tunnel and configure the proxy server 127.0.0.1 in the browser. The port is 9050, in this way, you can use the TOR proxy securely without worrying about the possibility of listening from our machine to the host www.chaifeng.com.

Plink-C-N-l 9050: 127.0.0.1: 9050 taylor@www.chaifeng.com

Combined with pscp, we can also complete daily file backup

Plink taylor@192.168.6.200 tar JCF $ (date 'your documents.f.tar.bz2 ')~ /Documents
Pscp taylor@192.168.6.200: $ (date 'your documents.f.tar.bz2 ') C:/backup/
Plink taylor@192.168.6.200 Rm-F $ (date 'your documents.f.tar.bz2 ')

If you want to write these common operations to a batch of processing files, restart tomcat, view Tomcat logs immediately, or simply re-dial the ADLs, you only need to double-click the batch processing file with the mouse. It will be automatically completed after a moment. Isn't it convenient to open putty, log on to the server, execute commands one by one, and finally log off?

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.