Run Commands Remotely via SSH with No Password
转自http://www.dotkam.com/2009/03/10/run-commands-remotely-via-ssh-with-no-password/
Extremely useful for system administrators, very useful for application developers when testing with remote services, or how some buzz developers refer to it: Service Oriented Architecture (SOA). Also remote execution is widely used by web masters to sync/backup/create mirrors.
Below 5 simple steps will enable you to run any commands on the remote box/host/server via SSH without a need to provide a password. That is usually useful, if such remote calls need to be automated (work without manual/human intervention).
Step number 6 has an example on how to actually run a command on remote host via SSH.
from the local host
Step 1. Create a public/private keys with “ssh-keygen” (ENTER through everything):
user@host:~/.ssh$ ssh-keygen -t rsaGenerating public/private rsa key pair.Enter file in which to save the key (/home/toly/.ssh/id_rsa): [ENTER]Enter passphrase (empty for no passphrase): [ENTER]Enter same passphrase again: [ENTER]Your identification has been saved in /home/user/.ssh/id_rsa.Your public key has been saved in /home/user/.ssh/id_rsa.pub.The key fingerprint is:66:fd:11:ca:2d:21:b9:73:c1:b6:fa:1d:b2:2c:71:cd user@hostThe key's randomart image is:+--[ RSA 2048]----+| || . || . o || o + o || E S.o o || o. .+.o . || . +o o. || +. o... || ... ..=. |+-----------------+ |
At this point the public and private keys should be created and saved into “~/.ssh” directory:
user@host:~/.ssh$ ls -ltotal 20-rw------- 1 user group 1675 2009-03-10 14:18 id_rsa-rw-r--r-- 1 user group 392 2009-03-10 14:18 id_rsa.pub-rw-r--r-- 1 user group 8642 2009-03-10 12:10 known_hosts |
Step 2. Add identity to the local ssh authorizer with “ssh-add”.
If you “entered” through the “Enter file in which to save the key (/home/toly/.ssh/id_rsa)” in the previous step, then your identity file should be “id_rsa”:
user@host:~/.ssh$ ssh-add id_rsa |
Otherwise replace “id_rsa” with the file you chose to save your identity in.
In case of a friendly “Could not open a connection to your authentication agent.” error message, start “ssh-agent” as:
eval `ssh-agent` |
and re-run “ssh-add”.
Step 3. Copy the public key to the remote host ( server ) under “~/.ssh”:
From the step above “id_rsa.pub” would be the public key that needs to be copied to the remote system you would like to run commands on.
user@host:~/.ssh$ scp id_rsa.pub remoteuser@remotehost.com:~/.ssh/ |
from the remote host
Step 4. On remote host add this public key to “authorized_keys”:
remoteuser@remotehost:~$ cd ~/.ssh |
remoteuser@remotehost:~/.ssh~$ cat id_rsa.pub >> authorized_keys |
Step 5. Change “authorized_keys” permissions to allow only you to read/write it:
remoteuser@remotehost:~/.ssh$ chmod 600 authorized_keys |
from the local host
Step 6. Now you can run any command on the remote box from the local box with no password:
Let’s see what that remote box is running at:
user@host:~$ ssh remoteuser@remotehost.com uname -aLinux remotehost 2.6.27-01-generic #1 SMP Thu Mar 21 10:34:21 UTC 2009 i686 GNU/Linux |
By runing “ssh remoteuser@remotehost.com uname -a” from the local box, you just ran “uname -a” command on the remote box without a need to enter the password.
Good Luck Remoting!
Run Commands Remotely via SSH with No Password相关推荐
- arch linux 密码正确也无法用root登录ssh 提示 Failed password for root from x.x.x.x port xxxx ssh2解决办法
arch linux 无法以root登录ssh解决办法 1.检查sshd 2.添加用户 添加sudo root权限 附 安装sshd 1.检查sshd 先停止sshd 在启用控制台消息的情况下运行它, ...
- 无法建立SSH链接和Password Authentication Failed,Please verify that the username and password are correct解决
因为我的Ubuntu中未安装ssh服务,终端下运行命令: sudo apt-get install openssh-server 之后重启一下ssh服务: sudo service sshd re ...
- ssh错误 Failed password for
登录一直被拒接,检查sshd的状态如下: 后来尝试用普通用户登录,发现可以成功登录,也就是root用户不能登录, 所以,修改ssh配置,加入 PermitRootLogin yes ,重启sshd,r ...
- Password-less logins with OpenSSH
2019独角兽企业重金招聘Python工程师标准>>> Because OpenSSH allows you to run commands on remote systems, s ...
- python第三方库排行-Python常用第三方库总结
网络爬虫 网络请求 requests: Requests allows you to send HTTP/1.1 requests extremely easily. 一个处理http请求的客户端库, ...
- 如何在Windows 10上安装PowerShell 7
Microsoft 微软 Microsoft announced PowerShell 7.0 on March 4, 2020. It's the latest major update to Po ...
- ubuntu安装ssh无法连接解决日志(已解决,可连接)-转
网上有很多介绍在Ubuntu下开启SSH服务的文章,但大多数介绍的方法测试后都不太理想,均不能实现远程登录到Ubuntu上,最后分析原因是都没有真正开启ssh-server服务.最终成功的方法如下: ...
- 在CISCO交换机上配置SSH
在Cisco路由器产品系列中只有7200系列.7500系列和12000系列(GSR)等高端产品的IOS支持SSH.一般支持SSH的IOS版本文件名中都带有K3或者K4字样,K3 代表56bit SSH ...
- ssh连接远程主机执行脚本的环境变量问题
http://www.kuqin.com/shuoit/20141113/343188.html 近日在使用ssh命令ssh user@remote ~/myscript.sh登陆到远程机器remot ...
最新文章
- anaconda怎么使用编写python_怎样使用anaconda编辑python
- 关于数据库中存储过程 的用户从属。。
- 微信开发:微信js_sdk 分享,前端部分(二)
- Python 字典类型的使用
- 上传文本到hdfs上的一些命令
- css div设置inline-block后 div顶部对齐
- golang 排序_堆 堆排序 优先队列 图文详解(Golang实现)
- 曝iPhone 12 Pro耗电异常,没开启任何应用电量也急剧下降
- 关于ASP.Net页面上用户控件相互调用的方法 .
- 2020年最好用的手机是哪一款_2020年换手机不用盲目,目前这4部最值得买,好看好用性价比高...
- c语言程序设计基础所有知识点,《C语言程序设计》基础知识点总结.doc
- 视频编码与封装方式详解
- 大学校园无线智能调频广播系统
- (第二天)编写训练记忆软件--数字编码矩阵V1.0
- twaver html5 api,TWaver版3D化学元素周期表
- 微信做音乐相册html5,如何制作微信音乐相册 微信音乐相册制作软件的精品教程...
- matlab升幂降幂排列,升幂排列与降幂排列
- (附源码)计算机毕业设计SSM科技类产品众筹系统
- 使用JSP做购物车一(实现)
- 1034: 夏季促销 C语言