Setting up SSH Public Key Authentication

简介:

ESXI 5: Setting up SSH Public Key Authentication
Leave a reply    

This tutorial describes the process on how you can connect via SSH to your ESXI 5.0 host using public key authentication. I have tried to explain as much as possible, since there (or at least I couldn’t find any) decent tutorials on the internet covering this subject on ESXI 5.0.

Firstly we will create our private and public keys on the remote host (the host we are connecting to ESXI on):

    
ssh-keygen -t rsa

The keys by default are stored as follows:

    
~/.ssh/rd_rsa
~/.ssh/rd_rsa.pub

We set the permissions:

    
chmod 600 ~/.ssh/rd_rsa
chmod 600 ~/.ssh/rd_rsa.pub

We will now copy the public key to the remote host:

    
scp ~/.ssh/rd_rsa.pub root@remotehost:/root

And then on the remote hosts we do:

    
cat /root/rd_rsa.pub > /etc/ssh/keys-root/authorized_keys
chmod 600 /etc/ssh/keys-root/authorized_keys

The above is very important, other tutorial do not explain this at all! There is a directive in /etc/ssh/sshd_config called “AuthorizedKeysFile /etc/ssh/keys-%u/authorized_keys” This specifies where a users “authorized_keys” will be looked up on the esxi host. In this tutorial we will be connecting from a remote host to the ESXI host as the user root; hence we replace %u with root – so it becomes “keys-root”.

Important!: Make sure that the ~/.ssh folders on both hosts are chmod to 700 e.g.:

    
chmod 700 ~/.ssh

In order to disable password logins to the SSH server you should change the following in :

    
vi /etc/ssh/sshd_config

and change according to below:

    
PermitRootLogin yes
ChallengeResponseAuthentication no # This entry might not be present! Don't add it if it isn't present.
PasswordAuthentication no

and finally restart SSH service:

    
/etc/init.d/SSH restart

You can now connect to ESXI 5 using SSH public key authentication by running the following:

    
ssh -i ~/.ssh/rd_rsa root@esxi-host

If you run into any problems, just use the -v switch in SSH e.g.:

    
ssh -v -i ~/.ssh/rd_rsa root@esxi-host
This entry was posted in Linux and tagged dropbear, esxi 5, public key, ssh on May 11, 2012.

 

补充:

禁止root登陆SSH,使用普通用户登陆,这样更安全,具体做法是:

a.添加用户:使用VMWare VSphere Client的“本地用户和组”(如果是使用域的,在“权限”中添加用户u)添加用户u,并“授权该用户shell程序访问权限”,组成员资格设定为“users”。

b.ssh登陆到esxi主机,然后

mkdir /etc/ssh/u

cat /root/rd_rsa.pub > /etc/ssh/keys-root/authorized_keys
chmod 600 /etc/ssh/keys-root/authorized_keys

chown u /etc/ssh/keys-root/authorized_keys

注意:要把所有者改为u,否则不能正常ssh登陆

c.修改/etc/ssh/sshd_config,不允许root身份登陆
    
PermitRootLogin no

d.重启动SSH服务
    
/etc/init.d/SSH restart

 

重启动esxi主机,悲剧了,root和用户u都不能登陆ssh了,只好通过esxi shell访问并调整了。

应该把authorized_keys文件放在/vmfs/volumes/datastore1/u/下,并把sshd_config中的文件指向新的位置:

AuthorizedKeysFile /vmfs/volumes/datastore1/u/authorized_keys

其他配置同上面;这样就能保证重启esxi主机后,authorized_keys文件仍然可用,不消失。










本文转自 h2appy  51CTO博客,原文链接:http://blog.51cto.com/h2appy/1106184,如需转载请自行联系原作者
目录
相关文章
|
Linux 网络安全 开发工具
百度搜索:蓝易云【Git安装 + 多站点SSH Key配置教程。】
现在,你已经成功安装了Git,并配置了多站点的SSH Key。你可以使用Git命令进行版本控制,并通过SSH Key进行身份验证来访问不同的Git仓库。
264 0
|
网络安全 开发工具 数据安全/隐私保护
解决 Enter passphrase for key ‘/Users/dzm/.ssh/id_rsa‘:
解决 Enter passphrase for key ‘/Users/dzm/.ssh/id_rsa‘:
4022 0
|
存储 网络安全
Curl error (60): SSL peer certificate or SSH remote key was not OK for https://update.cs2c.com.cn/NS/V10/V10SP2/os/adv/lic/base/x86_64/repodata/repomd.xml [SSL: no alternative certificate subject name matches target host name 'update.cs2c.com.cn']
【10月更文挑战第30天】在尝试从麒麟软件仓库(ks10-adv-os)下载元数据时,遇到 SSL 证书验证问题。错误提示为:`Curl error (60): SSL peer certificate or SSH remote key was not OK`。可能原因包括证书不被信任、证书与域名不匹配或网络问题。解决方法包括检查网络连接、导入 SSL 证书、禁用 SSL 证书验证(不推荐)、联系仓库管理员、检查系统时间和尝试其他镜像。
3715 1
|
安全 网络安全
jsch 报错 no matching host key type found. Their offer: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha> 如何处理
【5月更文挑战第24天】jsch 报错 no matching host key type found. Their offer: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha> 如何处理
1286 1
|
算法 网络安全
Unable to negotiate with 127.0.0.1 port 29215: no matching host key type found. Their offer: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha> 解决
【5月更文挑战第5天】Unable to negotiate with 127.0.0.1 port 29215: no matching host key type found. Their offer: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha> 解决
914 7
|
弹性计算 运维 Shell
基于key验证多主机ssh访问
【4月更文挑战第30天】
173 1
|
安全 网络安全
jsch 报错 no matching host key type found. Their offer: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha>问题处理方法
【5月更文挑战第10天】jsch 报错 no matching host key type found. Their offer: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha>问题处理方法
1012 0
|
算法 网络安全
no matching host key type found. Their offer: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha> 问题解决
【5月更文挑战第8天】no matching host key type found. Their offer: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha> 问题解决
4181 0
|
网络安全 数据安全/隐私保护
如何使用ssh key免密码登录服务器?
如何使用ssh key免密码登录服务器?
|
Shell Linux 网络安全
git实战—Gerrit配置SSH key & 下载代码到本地 & 使用VScode编辑器编辑提交代码——2023.07
git实战—Gerrit配置SSH key & 下载代码到本地 & 使用VScode编辑器编辑提交代码——2023.07
4555 0