Linux远程连接工具之ssh命令

环境:

linux: deepIn 15.11

windows: win7

前言

Secure Shell(SSH)是一种加密网络协议,用于在不安全的网络上安全地运行网络服务。 典型的应用程序包括远程命令行登录和远程命令执行,但是任何网络服务都可以使用SSH进行保护。

本文介绍如何使用ssh命令进行远程连接。

1.ssh服务端安装


# debian/deepin/ubuntu

sudo apt-get install openssh-server

# redhat/centos

sudo yum install openssh-server

# 启动ssh服务

sudo systemctl start sshd

# 设置ssh开机自启动

sudo systemctl enable sshd

ssh服务配置


vi /etc/ssh/ssh_config

2.ssh命令安装

2.1 linux


# debian/deepin/ubuntu

sudo apt-get install openssh-client

# redhat/centos

sudo yum install openssh-clients

2.2 windows

ssh在windows下的命令主要包括ssh.exe、scp.exe、sftp.exe

  • MobaXterm(★)

Windows增强版终端,支持SSH客户端、widnows终端(支持基本linux命令)、VNC、FTP、串口等协议等

version: MobaXterm Home Edition v20.2

https://mobaxterm.mobatek.net/

  • openssh

OpenSSH for Windows

version:setupssh-8.3p1-1.exe

https://www.mls-software.com

3.ssh命令的使用

3.1 ssh远程连接

用法


usage: ssh [-46AaCfGgKkMNnqsTtVvXxYy] [-B bind_interface]

          [-b bind_address] [-c cipher_spec] [-D [bind_address:]port]

          [-E log_file] [-e escape_char] [-F configfile] [-I pkcs11]

          [-i identity_file] [-J [user@]host[:port]] [-L address]

          [-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port]

          [-Q query_option] [-R address] [-S ctl_path] [-W host:port]

          [-w local_tun[:remote_tun]] destination [command]

连接到192.168.129.164的用户dev


ssh [email protected] -p 22


ssh [email protected] -p 22

[email protected]'s password:

Welcome to Deepin 15.11 GNU/Linux

    * Homepage:https://www.deepin.org/

    * Bugreport:https://feedback.deepin.org/feedback/

    * Community:https://bbs.deepin.org/

Last login: Thu Jun 25 18:10:26 2020 from 192.168.129.1

dev@dev-PC:~$ ls

b  b.txt  Desktop  Documents  Downloads  Music  Pictures  Videos  模板

3.2 ssh上传文件(夹)

  • scp命令(不需要连接ssh)

用法


usage: scp [-346BCpqrTv] [-c cipher] [-F ssh_config] [-i identity_file]

            [-J destination] [-l limit] [-o ssh_option] [-P port]

            [-S program] source ... target

ssh上传文件a.txt到~目录

ssh上传文件a文件夹到~目录


scp a.txt [email protected]:~

scp -r a [email protected]:~


scp a.txt [email protected]:~

[email protected]'s password:

a.txt                                        100%    0    0.0KB/s  00:00

scp -r a [email protected]:~

[email protected]'s password:

ssh [email protected] -p 22

dev@dev-PC:~$ ls -l

总用量 32

drwxrwx--- 2 dev dev 4096 6月  25 18:13 a

-rwxr-x--- 1 dev dev    0 6月  25 18:11 a.txt

-rw-r--r-- 1 dev dev    0 6月  25 18:17 b

-rw-r--r-- 1 dev dev    0 6月  25 18:18 b.txt

...

  • lzsz命令(需要连接ssh,需要SSH客户端支持)

安装


# debian/deepin/ubuntu

sudo apt-get install lrzsz

# redhat/centos

sudo yum install lrzsz

  • sftp命令(不需要未连接ssh)

sftp [email protected]

[email protected]'s password:

Connected to 192.168.129.164.

sftp> put C:/a.txt .

Uploading C:/a.txt to /home/dev/./a.txt

C:/a.txt                                                100%    0    0.0KB/s  00:00

sftp> ls

Desktop    Documents  Downloads  Music      Pictures  Videos    a.txt      b

b.txt      模板

3.3 ssh下载文件(夹)

  • scp命令(不需要连接ssh)

用法


usage: scp [-346BCpqrTv] [-c cipher] [-F ssh_config] [-i identity_file]

            [-J destination] [-l limit] [-o ssh_option] [-P port]

            [-S program] source ... target

ssh上传文件b.txt到当前目录

ssh上传文件b文件夹到当前目录


scp [email protected]:~/b.txt .

scp -r [email protected]:~/b .


scp [email protected]:~/b.txt .

[email protected]'s password:

b.txt                                        100%    0    0.0KB/s  00:00

scp -r [email protected]:~/b .

[email protected]'s password:

ls -l

total 2

drwxr-xr-x    1 win7    UsersGrp        0 Jun 25 18:07 a

-rw-r--r--    1 win7    UsersGrp        0 Jun 25 18:07 a.txt

drwxr-xr-x    1 win7    UsersGrp        0 Jun 25 18:19 b

-rw-r--r--    1 win7    UsersGrp        0 Jun 25 18:19 b.txt

...

  • lzsz命令(需要连接ssh,需要SSH客户端支持)

安装


# debian/deepin/ubuntu

sudo apt-get install lrzsz

# redhat/centos

sudo yum install lrzsz

  • sftp命令(不需要连接ssh)

sftp [email protected]

[email protected]'s password:

Connected to 192.168.129.164.

sftp> get b.txt C:/

Fetching /home/dev/b.txt to C:/b.txt

你可能感兴趣的:(Linux远程连接工具之ssh命令)