scponly 密钥无密码scp登录

简介:

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

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 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 
 
注意:在这里补充一点,为防止. ssh 下的文件被利用,我们用chattr控制加强文件权限
 
#cd /home/scpuser/.ssh
#chattr +i *
 
 
# 拷贝id.rsa到我们指定的客户服务器上
# scp /home/scpuser/.ssh/id.rsa clientserver:/www/


进入clientserver

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
[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
 
注意:
如果 sftp 不能用-i指定认证文件
sftp : illegal option -- i
可以用:
[root@apclt www] #sftp -oIdentityFile=/tmp/id.rsa scpuser@server



本文转自 jackjiaxiong 51CTO博客,原文链接:http://blog.51cto.com/xiangcun168/1672065


相关文章
|
2月前
|
安全 Shell 网络安全
ssh配置无密码验证
ssh配置无密码验证要在SSH中配置无密码验证,您需要使用公钥验证【2月更文挑战第18天】
43 1
|
4月前
|
安全 Linux 网络安全
服务器设置 SSH 通过密钥登录
服务器设置 SSH 通过密钥登录
|
网络协议 Shell Linux
ssh免密登录服务器和scp的使用
ssh免密登录服务器和scp的使用
278 0
|
网络安全 数据安全/隐私保护
ssh实现秘钥登陆
ssh实现秘钥登陆
71 0
|
安全 网络安全 数据安全/隐私保护
ssh 安全 之 密钥登录
ssh 安全 之 密钥登录
166 0
|
存储 分布式计算 安全
SSH无密码验证
SSH无密码验证
164 0
|
网络安全 安全 开发工具
终端配置ssh秘钥登录
终端配置ssh秘钥登录
|
网络安全 数据安全/隐私保护
SSH密钥登录原理
Client 发送请求 login 请求 --> Server 接受请求 --> 根据 authorized_key 文件中的对应 Client 的 ip 地址的公钥对一串随机数进行加密 --> 将加密之后的随机数发送给 Client --> Client 使用私钥进行解密 --> 使用MD根据当...
1587 0
|
网络安全
当SSH免密登录的私钥被移动之后... ...
一、设置免密登录 在主机192.168.237.21通过ssh-keygen生成私钥及对应公钥,分发公钥到192.168.237.22、192.168.237.23主机上。
1104 0
|
Linux 网络安全 数据安全/隐私保护