Because the telnet protocol uses plain text transmission, it is not applicable in environments requiring secure login. Now it is usually used for port testing of network services:
The peer port 80 is enabled and communication is allowed. When the peer port is not enabled:
10. ssh remote login programssh[OPTIONS]...[user@]hostname[command]
The full name of ssh is Secure Shell, which provides Secure and encrypted communication between insecure network hosts. It is designed to replace other remote logon protocols.
[Root @ centos7 ~] # Ssh10.0.1.253Theauthenticityofhost '10. 0.1.253 (10.0.1.253) 'CAN' tbeestablished. ECDSAkeyfingerprintis96: bd: a3: a7: 87: 09: 1b: 53: 44: 4c: 9b: b9: 5f: b2: 97: 89. areyousureyouwanttocontinueconnecting (yes/no )? Yes # input yesWarning: Permanentlyadded '10. 0.1.253 '(ECDSA) tothelistofknownhosts.root@10.0.1.253' spassword: # enter the password Lastlogin: FriNov1109: 04: 012016from192. 168.78.20.[ root @ idc-v-71253 ~] # Logged on
If you directly log on to the host using the ssh command and the Host IP address, the default user root is used for Logon. If this is the first logon, you need to confirm that the authentication key of the host is added. When yes is entered, the local/root /. add a record for this host to ssh/known_hosts. You do not need to confirm the record for the next logon. Then you need to enter the user password. After verification, we get a shell of the target host, and we can execute the command in this shell.
Enter exit in the new shell to return to the original shell.
If you need to log on to a host frequently, but do not want to enter the password every time, you can set a password-free Logon:
[Root @ centos7 ~] # Ssh-keygen-trsaGeneratingpublic/privatersakeypair. enterfileinwhichtosavethekey (/root /. ssh/id_rsa): # Press ENTER Enterpassphrase (emptyfornopassphrase): # Press ENTER Entersamepassphraseagain: # Press ENTER Youridentificationhasbeensavedin/root /. ssh/id_rsa. # Private Key Yourpublickeyhasbeensavedin/root /. ssh/id_rsa.pub. # Public Key Thekeyfingerprintis: be: c3: d0: 02: 50: 35: 35: fe: 60: d6: 2f: 26: 96: f0: e1: e6root @ centos7Thekey 'srandomartimageis: + -- [RSA2048] ---- + |... O. o |. oo | .. *. |. * =. | .. S +. | o =. o. | + E | o. | .. | + --------------- + [root @ centos7 ~] # [Root @ centos7 ~] # Ssh-copy-id10.0.1.253/usr/bin/ssh-copy-id: INFO: attemptingtologinwiththenewkey (s), tofilteroutanythatarealreadyinstalled/usr/bin/ssh-copy-id: INFO: 1key (s) remaintobeinstalled--ifyouarepromptednowitistoinstallthenewkeysroot@10.0.1.253 'spassword: Numberofkey (s) added: 1 nowtrylogging1_themachine, with: "ssh '10. 0.1.253 '"andchecktomakesurethatonlythekey (s) youwantedwereadded. [root @ centos7 ~] #
The command ssh-keygen is used to generate the public key and the option-t specifies the key type. Then use the command ssh-copy-id to send the public key to the target host. Enter the user password of the target host. Then you can log on without a password:
[root@centos7~]#ssh10.0.1.253Lastlogin:FriNov1111:08:372016from10.0.1.254[root@idc-v-71253~]#
You can also remotely execute commands through ssh:
[Root @ centos7 ~] # Ssh10.0.1.252 "hostname" root@10.0.1.252 'spassword: # Enter Password idc-v-71252 # display command results [root @ centos7 ~] # Do not log on
Or manually copy the public key to the target host:
[Root @ centos7 ~] # Cat/root/. ssh/id_rsa.pub | ssh10.0.1.252 "cat->/root/. ssh/authorized_keys" root@10.0.1.252 'spassword: # enter the password [root @ centos7 ~] # Ssh10.0.1.252 # password-free login Lastlogin: ThuNov1014: 42: 112016from192. 168.78.135 [root @ idc-v-71252 ~] #
Option-p specifies the port for Logon:
[root@centos7temp]#ssh-p2210.0.1.252Lastlogin:FriNov1111:44:312016from10.0.1.254[root@idc-v-71252~]#
Set the Port in the server configuration file/etc/ssh/sshd_config. The default Port number is 22. If you change the Port number, remove the # Port 22 comment and Change 22 to the required Port, restart the sshd service sshd restart or systemctl restart sshd.
If another user needs to log on to the system, run ssh user @ host.
We can use the tar command in combination with ssh and pipelines to back up local (remote) files to remote (local ):
Tarzc/home/temp | sshuser @ host "tarxz" # back up the local temp directory to the remote sshuser @ host "tarcz/home/temp" | tarxz # back up the remote temp directory to the local directory
Option-L [bind_address:] port: host: hostport
[Root @ centos7 ~] # Ssh-L2222: 10.0.1.252: 2210.0.1.253Lastlogin: MonNov1410: 34: 432016from10. 0.1.254 [root @ idc-v-71253 ~] # Note that if exit is disconnected, the forwarding will also be terminated.
This command binds the local port 2222 and forwards all data sent to this port to port 22 of the target host 10.0.1.252 through the intermediate host 10.0.1.253, in this case, if you use ssh to log on to port 2222 of the local machine, the actual logon is host 10.0.1.252.
[root@centos7~]#ssh-p2222127.0.0.1Lastlogin:MonNov1410:34:562016from10.0.1.253[root@idc-v-71252~]#
The local loopback port 127.0.0.1 is bound by default. If it is bound to another address, bind_address is set according to the syntax.
Option-N indicates that the command is not executed. It is useful only when port forwarding is set.
Because the above port forwarding command ssh-L 2222:10. 0.1.252: 22 10.0.1.253 will log on to the intermediate host, and port forwarding will be terminated after exiting. If you use the-N option, it will not log on, and then run the command in conjunction with the shell background, it will be a good option to set port forwarding (but you must note that password-free login is required for the intermediate host ):
[root@centos7~]#ssh-N-L2222:10.0.1.252:2210.0.1.253&[1]12432[root@centos7~]#
The final symbol of the command & indicates that the command will be executed in the background. In the returned message, [1] indicates the background command number, and 12432 indicates the command PID. (The shell background commands will be described in later articles)
Option-R [bind_address:] port: host: hostport
For example, run the following command on 10.0.1.253:
ssh-R2222:10.0.1.252:2210.0.1.254
Then log on to 10.0.1.254:
[root@centos7~]#ssh-p2222localhostLastlogin:MonNov1410:40:442016from10.0.1.253[root@idc-v-71252~]#
This means that the remote host 10.0.1.254 (compared with 10.0.1.253) listens to port 2222, and then forwards all data sent to this port to port 22 of the target host 10.0.1.252. Then, when you log on to port 2222 of the local host in 10.0.1.254, the target host 10.0.1.252 is actually logged on through the intermediate host 10.0.1.253.
OPTION-o OPTION specifies the options in the configuration file (such as/etc/ssh/sshd_config)
-O StrictHostKeyChecking = no can be added to avoid entering yes during the first login.
11. scp Remote File copyingscp[OPTIONS]...[[user@]host1:]file1...[[user@]host2:]file2
The scp command uses the ssh protocol to encrypt data transmission. Similar to ssh logon, you need to enter the remote host user password.
For example, copy the file/root/tcp. sh from the remote host 10.0.1.253 to the local directory:
[root@centos7~]#scproot@10.0.1.251:/root/a.txt./root@10.0.1.251'spassword:a.txt100%1250.1KB/s00:00[root@centos7~]#
The command displays the transmission status (transmission percentage, size, speed, and time ).
Copying a local file to a remote location is nothing more than replacing the source and destination.
Option-P specifies the remote connection port (ssh service port), and-o ssh_option uses the ssh option.
Option-l limit transmission speed limit. The unit of limit is Kbit/s.
Similar to the command cp, option-r indicates the copy directory, and-p indicates the File Permission retention time.
12. netstat prints Network InformationOption-a displays all port information:
[root@centos7~]#netstat-aActiveInternetconnections(serversandestablished)ProtoRecv-QSend-QLocalAddressForeignAddressStatetcp000.0.0.0:ssh0.0.0.0:*LISTENtcp00localhost:smtp0.0.0.0:*LISTENtcp05210.0.1.254:ssh192.168.78.143:49583ESTABLISHEDtcp600[::]:commplex-main[::]:*LISTENtcp600[::]:4243[::]:*LISTENtcp600[::]:ssh[::]:*LISTENtcp600localhost:smtp[::]:*LISTENraw600[::]:ipv6-icmp[::]:*7raw600[::]:ipv6-icmp[::]:*7ActiveUNIXdomainsockets(serversandestablished)ProtoRefCntFlagsTypeStateI-NodePathunix2[ACC]STREAMLISTENING12807/run/systemd/privateunix2[ACC]STREAMLISTENING12815/run/lvm/lvmpolld.socketunix2[]DGRAM12818/run/systemd/shutdowndunix2[ACC]STREAMLISTENING16403/var/run/dbus/system_bus_socket....
Only some information is displayed here.
Option-t: Display TCP connection information
Option-n: Display IP addresses without domain name Conversion
Option-p: Display PID and program name
[root@centos7~]#netstat-antpActiveInternetconnections(serversandestablished)ProtoRecv-QSend-QLocalAddressForeignAddressStatePID/Programnametcp000.0.0.0:220.0.0.0:*LISTEN1358/sshdtcp00127.0.0.1:250.0.0.0:*LISTEN2162/mastertcp05210.0.1.254:22192.168.78.143:49583ESTABLISHED12044/sshd:root@pttcp600:::5000:::*LISTEN17222/docker-proxytcp6 0 0 :::4243 :::* LISTEN 16983/docker tcp600:::22:::*LISTEN1358/sshdtcp600::1:25:::*LISTEN2162/master[root@centos7~]#
Proto indicates the Protocol (including TCP and UDP); Recv-Q and Send-Q indicate the receiving and sending queues, which are generally 0, if the value is not 0, data is waiting for processing in the Local receiving or sending cache. Local Address and Foreign Address indicate the Local Address and remote Address respectively. State indicates the connection status, it corresponds to various TCP connection statuses. PID/Program name indicates the process number and Program name.
Option-l indicates only LISTEN connections are displayed.
[root@centos7~]#netstat-ntlActiveInternetconnections(onlyservers)ProtoRecv-QSend-QLocalAddressForeignAddressStatetcp000.0.0.0:220.0.0.0:*LISTENtcp00127.0.0.1:250.0.0.0:*LISTENtcp600:::5000:::*LISTENtcp600:::4243:::*LISTENtcp600:::22:::*LISTENtcp600::1:25:::*LISTEN[root@centos7~]#
Option-utable displays UDP connection information
Option-r indicates displaying route information
[root@centos7~]#netstat-rKernelIProutingtableDestinationGatewayGenmaskFlagsMSSWindowirttIfacedefault10.0.1.1030.0.0.0UG000ens3310.0.1.00.0.0.0255.255.255.0U000ens33172.20.71.00.0.0.0255.255.255.0U000ens32192.168.78.010.0.1.104255.255.255.0UG000ens33
Option-I: Display Interface Information
[root@centos7~]#netstat-iKernelInterfacetableIfaceMTURX-OKRX-ERRRX-DRPRX-OVRTX-OKTX-ERRTX-DRPTX-OVRFlgens3215001319610707703246000BMRUens3315002531238808802516050000BMRUlo6553625035890002503589000LRU
13. tcpdump network packet capture toolCommand tcpdump capture a network interface that conforms to the expression of the packet, and print the description of the packet content.
Option-I:
[root@idc-v-71253~]#tcpdump-iens33tcpdump:verboseoutputsuppressed,use-vor-vvforfullprotocoldecodelisteningonens33,link-typeEN10MB(Ethernet),capturesize65535bytes15:41:59.121948IP10.0.1.108.3693>239.100.1.1.websm:UDP,length5815:41:59.122191IP10.0.1.109.35673>239.100.1.1.websm:UDP,length5715:41:59.128282IP10.0.1.253.ssh>192.168.78.143.51694:Flags[P.],seq749565300:749565496,ack3522345564,win255,length19615:41:59.134127IP192.168.78.143.51694>10.0.1.253.ssh:Flags[.],ack196,win3977,length015:41:59.140319ARP,Requestwho-has10.0.1.31tell10.0.1.102,length4615:41:59.168328ARP,Requestwho-has10.0.1.37tell10.0.1.102,length4615:41:59.262235ARP,Requestwho-has192.168.10.150tell192.168.10.151,length4615:41:59.622090IP10.0.1.108.3693>239.100.1.1.websm:UDP,length5815:41:59.622178IP10.0.1.109.35673>239.100.1.1.websm:UDP,length57....
After the command is started, you can use-v or-vv to display more detailed information and capture data packets from ens33. The output shows the packet header information (including ARP, IP, TCP, UDP, and other protocols) of each sent or received packet ). This command does not specify expression, so all data packets are captured by default.
If you need to capture the data packet and analyze it through other programs (such as wireshark), you can use option-w file to write the data to the file, at the same time, you also need to use option-s 0 to specify the size of the captured data packet to 65535 bytes, so as to avoid data packets being truncated and cannot be analyzed.
In the real environment, the amount of data packets flowing through the network card is huge. You can use expressions to filter data packets. Each data packet must be filtered by an expression. Only when the expression value is true will the data be output.
Expression can contain conditions specified by one or more keywords. You can use and (or &), or (or |), not (or !) And parentheses () indicate the logical relationship between each keyword. You can use >,< to represent comparison and calculation. The keywords include:
Type keywords, such as host, net, port, and portrange, indicate the host, network segment, port number, and port segment respectively.
Direction keyword, such as src and dst, indicating the source and destination respectively.
Proto protocol keywords, such as fddi, arp, ip, tcp, and udp, indicate various network protocols respectively.
Due to space limitations, the following example will only describe the role of options and expressions and will not explain the output content:
Tcpdump-iens33dsthost10.0.1.251 # monitor all packets sent from Port ens33 to host 10.0.1.20., the host can also be a host name tcpdump-ieth0host! 211.161.223.70and! 211.161.223.71anddstport80 # listening port eth0, capture the tcpdump tcpport80and (ip [2: 2]-( ip [0] & 0xf) <2)-(tcp [12] & 0xf0)> 2 ))! = 0) andsrcnet (183.60.w.or122.13.220) '-s0-ieth0-wipdump # capture the source or destination port is 80, and the source network is (183.60.190.0/24 or 122.13.220.0/24), and contains data, not SYN, FIN, ACK-only, and other TCP data packets without data are written to the file ipdump # note that the expression here is caused by single quotes to avoid syntax errors caused by shell parsing of special characters. tcpdump 'tcp [tcpflags] & (tcp-syn | tcp-fin )! = 0 and! Srcanddstnet10.0.0 '# print only the TCP start and end packets (SYN and FIN tags), and the source and target network segments are not 10.0.0.0/24tcpdump 'gateway10. 0.1.1andip []> 576 '# capture IP packets sent to the gateway 10.0.1.1 and greater than 576 bytes
There are many network-related commands, so I hope they can help you.
From: http:// OS .51cto.com/art/201612/524450.htm
Address: http://www.linuxprobe.com/linux-net-command.html