Linux SSH Command Example Guide

Source: Internet
Author: User

If you've been in the IT circle for a long time, you should have heard about SSH's great tool and its security features. This tutorial allows you to master the technology of connecting to remote computers securely and conveniently via SSH in a short period of time.

If you don't have any ideas about SSH, you can go to Wikipedia to get a sense of it.

Basic usage

The simplest SSH command only needs to specify the user name and host name parameters. The host name can be an IP address or a domain name. The command format is as follows:

    1. $ SSH [email protected]

For example, to log in to a Raspberry Pi system on my LAN, simply enter the following command at the command line:

    1. $ SSH [email protected]. 42.0. -

The PI and 10.42.0.47 in the command are the username and LAN IP address of my Raspberry Pi system, respectively. The host name needs to be changed to the IP address of your target host (local area network or remote) in actual use.

If you can successfully log in, then the following content is easy for you.

Use a different port

SSH is connected by default to port 22 on the target host, but you may need to connect to a different port for a variety of reasons.

    1. $ ssh -p 10022 [email protected]

The above command is to specify a port number of 10022 by adding the parameter-p.

Remote execution commands

Sometimes it is convenient to perform a command on a remote host and display it locally, and then continue to work locally. SSH will be able to meet this requirement:

    1. $ SSH [email protected]. 42.0. ls -l

For example, this command enumerates the contents of the remote host's home directory and displays it locally. Isn't it cool? You can try the other commands to see.

Mount Remote File system

Another great SSH-based tool called SSHFS. SSHFS allows you to mount the remote host's file system directly locally.

    1. $ SSHFS -o idmap=User [email protected]:/home/user ~/Remote

For example, the following command:

    1. $ SSHFS -o idmap=User [email protected]. 42.0. A:/home/pi ~/pi

This command mounts the home directory of the remote host Pi user to the Pi folder under the local landlord directory.

To learn more, you can refer to the SSHFS tutorial.

X11 graphical interface

If now you want to run a GUI program on the remote host, SSH has helped you to think of it! Using the previously mentioned SSH basic command plus parameter-X to connect to the remote host can turn on the X11 forwarding function. You may feel no difference after logging in, but when you run a graphical interface program you will find a different one.

    1. $ ssh -X [email protected]. 42.0. -
    2. $ pistore

If you want to do something else while running the graphical interface program, simply add a & symbol to the end of the command.

    1. $ pistore&

Escape character

SSH provides a variety of escape character functions. Connect to any remote host with SSH and enter ~? You can see a list of supported escape characters and feature descriptions. The following examples show the effects of ~# and ~c .

Configuring SSH

If you need to change the configuration of SSH, please open /etc/ssh/sshd_config for editing with your favorite text editor. For example, if you want to change the login banner, find the following line in the config file:

    1. #Banner None

Remove the # character (uncomment the line), and replace none with the address of the file that contains the content you want to display. The line should look like this when modified:

    1. Banner /etc/issue

In profile /etc/ssh/sshd_config You can also find configuration items such as port number, idle timeout, and so on. Configuration items are generally easier to understand, but it's safe to refer to the Help documentation under SSH when you modify some of the configuration items that are not quite certain.

Build SSH key Pair

Run the following command to create the key pair:

    1. $ ssh-keygen -t DSA

This command asks you to enter a password (which can be left blank) and then generates the key and displays a random graph of the key.

Looking for the master secret key

Before you prepare to add the key, you may want to use the following command to see if you have added the corresponding host key.

    1. $ ssh-keygen -F 10.42. 0.47

Delete the host secret key

In some cases, such as a host address change or no longer using a key, you may need to delete a key.

    1. $ ssh-keygen -R 10.42. 0.47

You can delete it with the above command. This is much more convenient than manually deleting in the ~/.ssh/known_hosts file.

Summarize

With the above content you should be able to easily use SSH. There are many things you can do to find out about SSH, which depends on your imagination.

Linux SSH Command Example Guide

Related Article

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.