Key login for SSH normal user (non-root user)

Source: Internet
Author: User
Tags chmod

key login for SSH normal user (non-root user)

This takes the username Zhangsan as an example.

Because of personal habits, I changed the user Zhangsan default directory, in the process of using the key to log in, always prompted to enter the user password, and/var/log/secure also did not have any information,
Later in the/etc/passwd the default directory changed back to/home/zhangsan, it is normal. Cause I've been tossing around all day ...

The following is a brief description of the key login steps for SSH non-root user:

1, generate key pair (key pair)

Ssh-keygen-t rsa-c "Zhangsan@mail.com"

Enter file in which to save the key (/ROOT/.SSH/ID_RSA):
#输入key的保存位置, you can enter directly.

Enter passphrase (empty for no passphrase):
#私钥口令, do not need to return directly to the word.


2, add public key to Authorized_keys file

Mkdir/home/zhangsan/.ssh
touch/home/zhangsan/.ssh/authorized_keys
cat/root/.ssh/id_rsa.pub >/home/ Zhangsan/.ssh/authorized_keys

Note Permissions for directories and files
/home/zhangsan/.ssh's owner is supposed to be zhangsan:group.
chmod 700/home/zhangsan/.ssh
chmod 600/home/zhangsan/.ssh/authorized_keys

Login Test
Ssh-i/home/zhangsan/.ssh/id_rsa zhangsan@127.0.0.1

If it is Xshell and other client tools, import the private key Id_rsa.

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.