Linux set SSH automatic login (password free, username)

Source: Internet
Author: User
Tags ssh rsync

Example One

1, create public key, public key

SSH-KEYGEN-T RSA

Copy the public key to the remote host

Ignore it out of any hint, merry all the way back to the end of it.

2. Copy the public key id_rsa.pub to the/HOME/USERNAME/.SSH directory of the remote machine and name it Authorized_keys

Method 1: One step in place: SCP ~/.ssh/id_rsa.pub Username@hostname:~/.ssh/authorized_keys

Method 2: Copy SCP ~/.ssh/id_rsa.pub username@hostname:~

Login SSH Username@hostname

Append Cat id_rsa.pub >> Ssh/authorized_keys

All kinds of means, as you happy, anyway copy the past on a number of remote host replication ~ If you are the local landing users and remote landing users in line, you can direct SSH hostname direct Landing, the following do not have to see.

3, the resolution of local landing users and remote landing users inconsistent


OK, this thing is very tangled, although do not have to enter the password, but still have ssh username@hostname to login, very uncomfortable, you understand. In fact, the solution is also very simple (but is my colleague told me, face a red), modify the local landing user's ~/.ssh/config file, if the wood has to build a bar, the contents are as follows:

Host hostname
User username
Host hostname2
User UserName2

In this way, the local and remote login user name inconsistency can also be ssh hostname landing.


Example Two


To run a command on a:

# ssh-keygen-t RSA (three consecutive returns, that is, the public and private keys are generated locally, no password is set)

# SSH root@192.168.1.10 "mkdir. SSH" (create. SSH directory on 1.10, you need to enter a password)

# SCP ~/.ssh/id_rsa.pub root@192.168.1.10:.ssh/id_rsa.pub (need to enter password)

The Order on B:

# Touch/root/.ssh/authorized_keys (If this file is already present, skip this one)

# cat/root/.ssh/id_rsa.pub >>/root/.ssh/authorized_keys (append id_rsa.pub content to

In Authorized_keys)

Back to a machine:

# SSH root@192.168.1.10 (no password required, login successful)

Do rsync sync on the B machine without having to enter a password or use a password file.

Rsync-avzu--progress--delete root@192.168.1.9:/var/www//var/www (192.168.1.10 client execution)

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.