Configure SSH Key-Based Authentication on a Linux Server(CentOS 7)

There are a few different ways of logging into an SSH server, SSH-key-based authentication and password-based authentication are the most basic methods . Here we'll focus on the SSH-key based authentication.

 

Before we go, make sure we have the SSH key on the local computer.

path: ~/.ssh

create a SSH-key if necessary:

ssh-keygen

(optional)copy the public key to the clipboard:

pbcopy < ~/.ssh/id_rsa.pub 

 

Option1: Copy the public key to the remote server: 

ssh-copy-id username@remote_host

 

Option2: Logging into the remote server and check if the authorized_keys file is exists.

path: ~/.ssh/authorized_keys

create the .ssh directory and the authorized_keys if necessary

mkdir .ssh
touch ~/.ssh/authorized_keys

copy the public key to authorized_keys

echo public_key_string >> ~/.ssh/authorized_keys

 

(optional) Disable Password Authentication on the Server

sudo vi /etc/ssh/sshd_config

Inside the file, search for a directive called PasswordAuthentication. This may be commented out. Press i to insert text, and then uncomment the line and set the value to "no". This will disable your ability to log in via SSH using account passwords. To actually implement these changes, we need to restart the sshd service:

sudo systemctl restart sshd.service

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值