Create an ssh key:

ssh-keygen

Copy an SSH key to a remoate server:

ssh-copy-id root@104.197.227.8  // username@ip address / hostname

Then enter your password.

To make sure you can SSH into remote server, you can do:

ssh root@104.197.227.8

Since ssh-copy-id is just a helper script, let's find it what it's actually doing in the event we want to manually add keys for authentication in the future. After SSHing into the remote host, go into the .ssh folder within your home directory. Within that folder will be a file named authorized_keys. This file contains a list of public SSH keys which have been granted access for authentication. We can see that our public SSH key has been added to this file. Public key added to authorized_keys.

SSH into a remote server:

Normal way to do it:

ssh root@104.197.227.8

If you need to do more configuration:

ssh -p  -i ~/.ssh/another_key root@104.197.227.8
// Let's assume the SSH server is bound to port 2022 instead of port 22. We add a -p flag followed by our port number 2022. Another command flag that is important is the -i flag. The i stands for identity and allows us to specify a different SSH key to authenticate with. This makes it possible to set up any number of different SSH keys to connect to any number of different hosts.

SSHing into a remote host drops you right into a bash shell, but you may just want to run one command and immediately exit. Instead of dropping a newer bash shell you may specify a command to run after typing in your connection string. This allows you to run one-off commands, a quick bash script, or anything else you wish without needing to create and stay within an SSH session.

ssh root@104.197.227.8 hostname // get hostname and exit

Simplify connections with SSH config files:

Using SSH config files to greatly simplify SSH connections to remote hosts, use hostname aliases, and set advanced directives such as Port and IdentityFile settings per host

Create a config file:

vi ~/.ssh/config
Host foo  // alias for the host
HostName 104.197.227.8 // define the actul hostname or ip address
IdentityFile ~/.ssh/id_rsa // if needed, tell using a different public key
Port // if needed, change the port

SSH into a host:

ssh foo

Use scp to securely copy files remotely over SSH:

To use the secure copy command to copy the file to the remote host, type scp followed by the file you wish to copy, in this case bar.txt. Then specify your username @remotehost connection string, and suffix it with a colon. After the colon is where to tell scp where to copy the file to on the remote host. In this case, copy it to the home directory.

scp bar.txt mark@myhost.com:~/bar.txt

By default, scp will use your default SSH key to connect to the remote host. To specify a different SSH key or identity, use the -i flag followed by the location of your SSH private key.

scp -i ~/.ssh/another bar.txt mark@myhost.com:~/

You can also copy the whole folder by using `-r` command:

scp -r foo mark@myhost.com:~/bar.txt // copy the whole foo folder

Copy the fild from remote host to local host:

scp mark@myhost.com:~/bar.txt ./new.txt

[SSH] Intro to SSH command的更多相关文章

  1. 第1章 ssh命令和SSH服务详解

    基础服务类系列文章:http://www.cnblogs.com/f-ck-need-u/p/7048359.html 本文对SSH连接验证机制进行了非常详细的分析,还详细介绍了ssh客户端工具的各种 ...

  2. Linux中ssh介绍与ssh+key密钥登陆部署

    环境内核信息: [root@zabbix- ~]# uname -a Linux zabbix- -.el6.x86_64 # SMP Tue Mar :: UTC x86_64 x86_64 x86 ...

  3. Mac和window生成ssh和查看ssh key

    一.MAC系统 mac 系统开始就已经为我们安装了ssh 如果没有安装,首先安装 打开终端:$ ssh -v 查看ssh版本 OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec ...

  4. 【转】linux下安装ssh服务器端及ssh的安全配置

    一.在服务器上安装ssh的服务器端. $ sudo apt-get install openssh-server 2. 启动ssh-server. $ /etc/init.d/sshrestart 3 ...

  5. [SSH服务]——一个SSH无密码登陆实验

    实验拓扑图 实验描述 机房内有两台服务器: (1)B服务器10.0.10.158,充当Web服务器,有普通用户user_00 (2)C服务器10.0.10.191,充当Mysql服务器,有普通用户us ...

  6. Hadoop SSH+IP、SSH+别名 免密登录配置

    1.为什么要进行 SSH 无密码验证配置? Hadoop运行过程中需要管理远端Hadoop守护进程,在Hadoop启动以后,NameNode是通过SSH(Secure Shell)来启动和停止各个Da ...

  7. SSH 协议的 ssh StrictHostKeyChecking

    项目的SFTP用到了这个参数: @Override public PooledObject<ChannelSftp> makeObject() throws Exception { JSc ...

  8. 通过Obfuscated ssh避免时不时ssh连接不畅的问题【转】

    众所周知的原因,为了能流畅的使用google.使用某些“不存在”的网站,我们一般都是需要通过某些不方便光明正大说明使用用途的技术.比如通过ssh tunnel,这是最简单的,也是用得最多的. 不过,这 ...

  9. Linux之间配置SSH互信(SSH免密码登录)

    为简化SSH过程,采用证书方式,免去SSH登入时需要输入账号密码的过程,具体操作如下: 一.在SSH服务器所在机器上 1.以root用户登录,更改ssh配置文件 /etc/ssh/sshd_confi ...

随机推荐

  1. linux-socket connect阻塞和非阻塞模式 示例

    ~/cpp$ ./connect 192.168.1.234 1234 kkkk block mode:  ubuntu 14.04 : time used:21.0.001053s connect ...

  2. ASP.NET Web API实践系列07,获取数据, 使用Ninject实现依赖倒置,使用Knockout实现页面元素和视图模型的双向绑定

    本篇接着上一篇"ASP.NET Web API实践系列06, 在ASP.NET MVC 4 基础上增加使用ASP.NET WEB API",尝试获取数据. 在Models文件夹下创 ...

  3. 再议ASP.NET MVC中CheckBoxList的验证

    在ASP.NET MVC 4中谈到CheckBoxList,经常是与CheckBoxList的显示以及验证有关.我在"MVC扩展生成CheckBoxList并水平排列"中通过扩展H ...

  4. java中Double类数字太大时页面正常显示而不要用科学计数法

    /** * 当浮点型数据位数超过10位之后,数据变成科学计数法显示.用此方法可以使其正常显示. * @param value * @return Sting */ public static Stri ...

  5. python测试开发django-43.session机制(登录/注销)

    前言 当我们登录访问一个网站时,服务器需要识别到你已经登录了,才有相应的权限访问登录之后的页面.用户退出登录后,将无权限访问再访问登录后的页面. 从登录到退出的一整个流程,可以看成是与服务器的一次会话 ...

  6. WinForm IME输入法BUG完美修复

    本文来自http://hi.baidu.com/wingingbob/item/a2cb3fc0fe3bd1bb0d0a7b5b <WinForm IME输入法BUG测试>里,我描述了在. ...

  7. Easyui layout设置满屏效果

    html文件: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" ...

  8. [Android Pro] 组件化:企业级大型项目必经之路

    cp : https://www.csdn.net/article/2011-02-11/291667 摘要:超过一年以上.活跃开发的项目往往到后期陷入了一些共性的问题: 构建速度慢,往往生成一次最终 ...

  9. SVG.js Marker标记和自定义标签

    一.SVG.Marker 添加标记 SVG.Marker 标记可以被添加到一个线,折线的各点,多边形和路径.有三种类型的标记:开始,中间和结束.如果开始表示第一个点,则结束中间的最后一点和中间点. v ...

  10. H2:开源内存数据库引擎

    本资源由 伯乐在线 - 刘立华 整理 H2是一个开源的内存数据库.Java编写.快速.小巧(1.5MB jar包)还提供了Web控制台管理数据库内容. 主要功能 非常快速的数据库引擎. 开源. Jav ...