歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> 學習Linux >> Centos7 配置登錄服務器

Centos7 配置登錄服務器

日期:2017/3/3 17:46:10   编辑:學習Linux

Centos7 配置登錄服務器

Centos7 配置登錄服務器


概述

本文描述使用 Centos7 系統作為登錄服務器的配置。

在自動化運維的過程中,如果使用 Ansible 基於 SSH 來管理服務器,就可以將 Ansible 部署在登錄服務器上,登錄服務器需要可以通過 SSH 秘鑰方式登錄被管理的服務器。

配置過程

1 使用 root 用戶創建新用戶ops,並設置密碼

# useradd ops# passwd ops

2 配置 sudo 權限,設置 ops 用戶無密碼使用 sudo

# visudo

增加ops ALL=(ALL) ALL

## Allow root to run any commands anywhereroot    ALL=(ALL)       ALLops     ALL=(ALL)     NOPASSWD:ALL

3 生成 ops 用戶的秘鑰

# su ops$ ssh-keygen -t dsa
  • 秘鑰位置默認在/home/ops/.ssh/
  • 生成秘鑰時輸入請設置私鑰密碼(passphrase)

處於安全考慮,不建議生成私鑰時不設置私鑰密碼。生成私鑰密碼後,每次使用私鑰時,需要輸入私鑰密碼才能使用。

4 被管理的服務器創建用戶

首先在被管理的服務器中創建 ops 用戶並設置密碼

useradd opspasswd ops

配置 sudo

# visudo

增加ops ALL=(ALL) ALL

## Allow root to run any commands anywhereroot    ALL=(ALL)       ALLops     ALL=(ALL)     NOPASSWD:ALL

5 上傳公鑰

前往登錄服務器,將 ops 用戶的公鑰復制到被管理的服務器,請將下列 IP 更換為您的被管理服務器 IP

ssh-copy-id -i /home/ops/.ssh/id_dsa.pub [email protected]

到這裡,已經可以在登錄服務器中使用秘鑰來登錄被管理的服務器,然而每次登錄都需要輸入私鑰密碼,並不方便,下邊通過配置 keychain 來緩存私鑰密碼。

6 keychain 配置

在登錄服務器中安裝 keychain,Centos7 下需要使用擴展的 yum 源,安裝這個源

rpm -Uvh http://packages.psychotic.ninja/7/base/x86_64/RPMS/psychotic-release-1.0.0-1.el7.psychotic.noarch.rpm

安裝 keychain

yum --enablerepo=psychotic install keychain

編輯/home/ops/.bash_profile,加入如下內容

/usr/bin/keychain ~/.ssh/id_dsa source ~/.keychain/$HOSTNAME-sh > /dev/null

在登錄服務器每次重新啟動後,使用 ops 用戶首次登入登錄服務器時,會提示輸出私鑰密碼,之後登錄服務器會緩存私鑰密碼,在之後使用私鑰時就不需要輸入私鑰密碼了。

http://xxxxxx/Linuxjc/1184769.html TechArticle

Copyright © Linux教程網 All Rights Reserved