Linux with Linux and Linux and Windows using key login

Source: Internet
Author: User

1. Trust relationship

1) Linux trusts Linux:

Host 1:

ssh-keygen-t RSA(generate key pair)--Enter using default

scp/root/.ssh/id_rsa.pub [email protected] host 2_ip:/home/ (copy the public key to a host that does not need to be verified)

Host 2: Create the. ssh folder for the user host directory (permission is 700)

cat id_rsa.pub >> Ssh/authorized_keys (Authorized_keys permission is 600)


Authoized_keys files can trust multiple hosts at the same time, so use append


2) Linux trusts windows:

Using SECURITYCRT to generate an RSA key pair, you can enter a peer phrase when generating a key pair, and if you enter a passphrase, you will be prompted to enter a passphrase when you log in

Upload the corresponding identity.pub to the Linux server and use the

cat identity.pub >> ssh/authorized_keys (Authorized_keys permissions are also set to 600)


3. Use the key when using SSH login

Modify Linux:vim/etc/ssh/sshd_config

(1) Protocol 2 #仅允许使用SSH2

(2) port #使用22端口, preferably modified to another port, and open the firewall corresponding port

(3) Permitrootlogin Yes #允许root直接登录, it is generally forbidden to log in directly by root

(4) Pubkeyauthentication Yes #启用公告密钥配对认证方式

(5) authorizedkeysfile. Ssh/authorized_keys #设定PublicKey文件路径

(6) Rsaauthentication Yes #允许RSA密钥

(7) Passwordauthentication no #禁止密码验证登录, if enabled, OpenSSH RSA authentication login is meaningless.

Restart SSHD Service Services sshd Restart

4, Result: Host 1 Login host 2 no longer need password, (user only to generate the key pair of the host 1 user-free Authentication login Host 2 reserved Public key user, one-to-one trust)



5. In the case of inability to log in directly with the root, add users who can switch to root with their own password only

Add users and give passwords

useradd-g Wheel User

echo ' user&123 ' |passwd user1--stdin

Modify Linux:vim/etc/sudoers

sed-i ' S/#%wheel all= (All) All/%wheel all= (All) all/'/etc/sudoers

At this time You can use sudo su and enter a password to switch to root permissions when you log in to the user of the wheel group.


This article is from the "we should know each other" blog, please be sure to keep this source http://lshunchang.blog.51cto.com/9242952/1600351

Linux with Linux and Linux and Windows using key login

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.