linux 实现无密码登陆 ---- sftp
2015-06-24 15:23
656 查看
sftp是基于ssh的,服务器在接收到连接请求时,应该会尝试查找客户端的公钥,如果找不到,或者找到的公钥不匹配,就会要求做用户名密码认证
SFTP 使用时不输入密码实现过程:
主要步骤如下:
1.为运行shell脚本的本地用户生成密钥对
2.将其中的公钥分发到sftp欲登录的远程服务器上
3.编写并以上面的本地用户运行shell脚本
一.生成密钥对
在shell脚本中使用sftp时必须用到密钥对(公钥和私钥).可使用下列方式生成(SSH 2.X版本),这里本地用户记为:local_user:
ssh-keygen -t rsa
屏幕提示:
Generating public/private dsa key pair.
Enter file in which to save the key (/home/local_user/.ssh/id_dsa):
# 按回车保存为: /home/local_user/.ssh/id_dsa,即当前用户local_user的私钥
Enter passphrase (empty for no passphrase):
# 按回车,表示读取密钥时不需要密钥的密码
Enter same passphrase again:
# 确认密钥的密码,必须和上面的输入相同
Your identification has been saved in /home/local_user/.ssh/id_dsa.
# 私钥保存信息
Your public key has been saved in /home/local_user/.ssh/id_dsa.pub.
# 公钥保存信息
The key fingerprint is:
ec:41:e8:08:38:0b:f8:1e:bc:92:98:32:fc:d7:69:7d ...
# 密钥指纹
二.分发公钥
为了使用密钥,必须将公钥分发到欲登录的远程服务器上,这里远程服务器记为remote_host,欲登录的远程用户记为remote_user
1.copy公钥到欲登录的远程服务器的远程用户的家目录下,例如:
copy id_dsa.pub到remote_host:/home/remote_user/.ssh/
若目录/home/remote_user/.ssh/不存在,请先创建之.
2.将copy来的公钥文件改名为authorized_keys
3.修改公钥文件的访问权限
chmod 644 authorized_keys
三.示例
目标:把某路径下的COBOL85.pco拷贝成aaaa
#!/bin/bash
sftp ntt12@172.23.16.55 << EOF
put /home/ntt12/work/WWW/COBOL85.pco /home/ntt12/work/WWW/aaaa
quit
[EOF]
SFTP 使用时不输入密码实现过程:
主要步骤如下:
1.为运行shell脚本的本地用户生成密钥对
2.将其中的公钥分发到sftp欲登录的远程服务器上
3.编写并以上面的本地用户运行shell脚本
一.生成密钥对
在shell脚本中使用sftp时必须用到密钥对(公钥和私钥).可使用下列方式生成(SSH 2.X版本),这里本地用户记为:local_user:
ssh-keygen -t rsa
屏幕提示:
Generating public/private dsa key pair.
Enter file in which to save the key (/home/local_user/.ssh/id_dsa):
# 按回车保存为: /home/local_user/.ssh/id_dsa,即当前用户local_user的私钥
Enter passphrase (empty for no passphrase):
# 按回车,表示读取密钥时不需要密钥的密码
Enter same passphrase again:
# 确认密钥的密码,必须和上面的输入相同
Your identification has been saved in /home/local_user/.ssh/id_dsa.
# 私钥保存信息
Your public key has been saved in /home/local_user/.ssh/id_dsa.pub.
# 公钥保存信息
The key fingerprint is:
ec:41:e8:08:38:0b:f8:1e:bc:92:98:32:fc:d7:69:7d ...
# 密钥指纹
二.分发公钥
为了使用密钥,必须将公钥分发到欲登录的远程服务器上,这里远程服务器记为remote_host,欲登录的远程用户记为remote_user
1.copy公钥到欲登录的远程服务器的远程用户的家目录下,例如:
copy id_dsa.pub到remote_host:/home/remote_user/.ssh/
若目录/home/remote_user/.ssh/不存在,请先创建之.
2.将copy来的公钥文件改名为authorized_keys
3.修改公钥文件的访问权限
chmod 644 authorized_keys
三.示例
目标:把某路径下的COBOL85.pco拷贝成aaaa
#!/bin/bash
sftp ntt12@172.23.16.55 << EOF
put /home/ntt12/work/WWW/COBOL85.pco /home/ntt12/work/WWW/aaaa
quit
[EOF]
相关文章推荐
- linux 添加用户、权限 - !!!!!!!!!!! - 博客园
- Synopsys VCS MX vJ-2014.12 SP2 Linux64 1DVD编译代码模拟器
- hello welcome to linux`s world
- 在CentOS 6.6操作系统下安装配置phpMyAdmin 4.3.13.1
- Linux类似迅雷的下载利器uGet
- 在Linux程序中输出函数调用栈
- Linux原始套接字实现分析
- linux下eclipse交叉开发环境搭建
- linux下安装svn记录
- linux操作系统-设置静态ip
- Linux 可执行文件结构与进程结构
- Linux编译安装 简版
- 详解Linux安装GCC方法(下载、解压缩、安装、卸载)
- 我在阿里云Linux服务器上的第一次操作
- linux邮箱系统sendmail惊魂
- [转]Linux中设置服务自启动的三种方式
- epoll 底层实现源码分析
- Linux下配置DHCP服务器
- 与linux相处的日子里
- 从裸机编程到嵌入式Linux编程思想的转变------分而治之:驱动和应用程序