码迷,mamicode.com
首页 > 其他好文 > 详细

scponly 密钥无密码scp登录

时间:2015-07-08 22:56:48      阅读:330      评论:0      收藏:0      [点我收藏+]

标签:scponly 密钥无密码scp登录

安装完scponly,发现只能用密码去登录,能不能利用密钥无密码登录呢?

答案是可以的:原文如下:

# install the scponly package 
sudo apt-get install scponly 

# create the scp user and set their login shell to be scponly 
sudo useradd -m -s /usr/bin/scponly scpuser 

# create the .ssh directory 
sudo mkdir /home/scpuser/.ssh 

# create a key pair 
sudo ssh-keygen -f /home/scpuser/.ssh/id.rsa (no passphrase if used for automated backups) 

# create the authorized_keys file using the public key 
sudo cp /home/scpuser/.ssh/id.rsa.pub /home/scpuser/.ssh/authorized_keys 

# correct the ownership (creating keys can‘t be done as scpuser as no login shell!) 
sudo chmod 755 /home/scpuser/.ssh 
sudo chmod 644 /home/scpuser/.ssh/authorized_keys 
sudo chown -R scpuser:scpuser /home/scpuser 

# 拷贝id.rsa到我们指定的客户服务器上
# scp /home/scpuser/.ssh/id.rsa clientserver:/www/


进入clientserver

[root@apclt www]# ssh -i id.rsa scpuser@server
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for ‘id.rsa‘ are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
bad permissions: ignore key: id.rsa
scpuser@server‘s password: 
Permission denied, please try again.
scpuser@server‘s password: 
#报权限错误,我们给这个文件赋权
[root@apclt www]# chmod 400 id.rsa 
[root@apclt www]# ssh -i id.rsa scpuser@server

Welcome to aliyun Elastic Compute Service!


The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

Last login: Mon Jul  6 21:45:21 2015 from 183.11.157.17
Connection to server closed.
#成功无密码登陆 但我们配置了SCPONLY所以无法成功登录

[root@apclt www]# scp -i id.rsa -r scponly-4.8 scpuser@server:
scponly-4.8                                         100% 1675     1.6KB/s   00:00



本文出自 “xiangcun168” 博客,请务必保留此出处http://xiangcun168.blog.51cto.com/4788340/1672065

scponly 密钥无密码scp登录

标签:scponly 密钥无密码scp登录

原文地址:http://xiangcun168.blog.51cto.com/4788340/1672065

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!