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

最新文章

  1. UML大战需求分析——阅读笔记03
  2. 15个最佳的代码评审(Code Review)工具
  3. db2 中文表名和字段
  4. jq中阻止元素的默认行为
  5. 使用XmlPullParser对xml进行读取
  6. Linux配置完iptables后,重启失效的解决方案
  7. [LeetCode]题解(python):149-Max Points on a Line
  8. linux学习历程
  9. 使IIS Express支持其他网络客户端访问
  10. Java IO流--练习2
  11. 操作Work、Excel、PDF
  12. VM下新建虚拟机并装linux系统
  13. H5拖动实现代码
  14. BZOJ3378:[USACO]MooFest 狂欢节(树状数组)
  15. Centos7 Install Kubernetes
  16. Java 实现 Http 请求工具类
  17. InstallShield Build错误:Internal build error 6041
  18. Linux定时任务工具crontab详解及系统时间同步
  19. Nginx 反向代理解决favicon404错误问题
  20. windows命令:control命令

热门文章

  1. how convert large HEX string to binary array ?
  2. 微信图片生成插件,页面截图插件 html2canvas,截图失真 问题的解决方案
  3. delphi DockPresident
  4. The .NET weak event pattern in C#
  5. 未经处理的异常:System.Net.Sockets.SocketException: 以一种访问权限不允许的方式做了一个访问套接字的尝试
  6. 解决ASP.NET MVC4中使用Html.DropDownListFor显示枚举值默认项问题
  7. .net连mysql数据库汇总
  8. Android按键添加和处理的方案
  9. Winfrom固定Label宽度,根据文本动态改变Label的高度 z
  10. Mysql数据库自带四个数据库的解析