Summary of linux Command ssh, linux Command ssh

Source: Internet
Author: User

Summary of linux Command ssh, linux Command ssh

Because the project requires a large amount of computing, You need to distribute tasks to multiple computers for running. Because you are not familiar with the distributed concept, you can think of the simplest ssh protocol in linux to remotely control other computers, then write a shell script to run the program on all computers. (my operating system is Ubuntu16.04)

First, run the following command on your computer to check whether ssh is installed.

Ps-e | grep ssh

 

If the returned result is sshd in, it indicates that ssh has been installed. Otherwise, the installation is online.

Sudo apt-get install ssh installation.

Next, when we use ssh to log on to another computer, ssh username @ ip will be logged on, and a prompt will be prompted to enter the password. At this time, enter the password to remotely control another computer.

 

(Ifconfig view ip address)

 

If you have ten computers that require you to connect to and assign tasks, you must remember the ip address and password of the computer every time. This is not conducive to the unified running of scripts, therefore, the first step is to allow password-free logon from a computer that requires remote control.

First, we generate a key on your computer.

Ssh-keygen, and enter all the way. The. ssh folder is generated in the main directory.

Ls-a (check whether the. ssh folder is generated)

Go to the. ssh folder and view the file.

 

The key pair has been generated. Next, copy the public key to the computer you want to connect to through scp.

Cat ~ /. Ssh/id_rsa.pub> ~ /. Ssh/authorized_keys

Scp ~ /. Ssh/id_rsa.pub username @ ip :~ /. Ssh/id_rsa.pub_copy

Next, remotely connect to the computer you need to connect as the server

Touch ~ /. Ssh/authorized_keys

Cat ~ /. Ssh/id_rsa.pub_copy> ~ /. Ssh/authorized_keys

At this time, the last step is to modify the permissions.

Chmod 755 ~

Chmod 700 ~ /. Ssh

Chmod 600 ~ /. Ssh/authorized_keys

Many people do not understand the meaning of the 755,700,600 data. This is a digital expression of linux permissions.

For example, when we view the permission of a file

 

We will see the above results. The previous part is composed of ten digits in the form of 1-3-3. The first letter indicates the file type, and d indicates the first letter of the document folder, the first three digits indicate the permissions of the owner, the second three digits indicate the permissions of the group, and the third three digits indicate the permissions of other groups. R -- read, W-write, and X-Execute. Therefore, rwx indicates that the current group is readable and writable. return to the preceding number. R corresponds to numbers 4, W corresponds to 2, and X corresponds to 1. now we can understand that 755 indicates that the owner is readable and writable, and the group is writable and executable. Other groups are also writable and executable.

Now, you can test whether you can log on to another user's computer without a password.

 

During the running process, you may encounter this problem. This indicates that the ssh-agent is running, but the corresponding key is not found. We can solve this problem through ssh-add, you can also use ssh-add-l to view the attached key.

 

In the remote connection, you still need to enter the user name and ip address. If you do not want to enter the user name, you can create the same user for all the computers at first.

Script to run all programs

Screen-dm ssh-t username1 @ ip1 "..." (enter the command you want to run in the quotation marks)

Screen-dm ssh-t username2 @ ip2 "..."

 

Ps: I hope you can give me more advice on poor writing.

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.