linux-Remote Operation essay

Source: Internet
Author: User

Summary of operations that connect and interact with remote environments


First class: Enter the command mode directly in the Linux environment

1) FTP [email protected] #回车之后需要输入密码

Or: FTP Remoteip #回车后提示输入用户名和密码

2) sftp sftp=ssh+ftp

Usage: Login In the same way as FTP

3) SSH It is equivalent to SFTP

Usage: equivalent to SFTP

4) SCP is SSH+CP

SCP Local_file [Email Protected]_ip:remote_folder

Copy the file to the remote directory, download the parameter in turn

Specific detailed connection: http://www.cnblogs.com/hitwtx/archive/2011/11/16/2251254.html

Recommendation: Using FTP and SSH commands is almost the same as on-premises environments, and it is not recommended to use SFTP

Class II: Connecting to the server through scripting and executing commands


1.ftp: Way

###########################################################

# mv.sh

#实现向多台远程机器传输文件, and set instructions such as executable

###########################################################

#!/bin/ksh

Root=root

Pwd=pwd

remoteips= ' 10.71.148.15 10.71.148.23 '

For IP in $remoteips

Do

Ftp-in $ip <<eof

User $root $pwd

CD/

put/user/local.txt/home/n

# Append + R to add permissions to all sub-files in the file directory

chmod 755 Local.txt

Bye

Eof

Done

2.expect: Expect and BSH these are the same, but executing different statements that do not support Xshell scripts

Reference: http://www.cnblogs.com/iloveyoucc/archive/2012/05/11/2496433.html

##############################################################

# mv.exp "suffix can be. Sh"

#实现向多台远程机器传输文件 but can't manipulate other instructions because you don't know

#什么时候执行完, what comes last

##############################################################

#!/usr/bin/expect-f

#睡眠10秒

Set Timeout 10

#set等价于 = definition Initialization

Set username root

#[lindex $argv 0|1|2 ...] Fixed format representing parameters passed in from outside

Set password [lindex $argv 0]

Set hostname [lindex $argv 1]

#spawn indicates that the Execute instruction r represents the file directory

Spawn SCP LocalFile [email protected] $hostname

#① here's {} like Swich.

expect{

#匹配到一个直接执行然后就跳出, there's no

"Yes/no" {send "yes\r"; expect "password:"; Send "$pasword \ n"}

"Password:" {send "$password \ r"}

}

#send "Exit\r"

Expect EOF


Test: Can be called through a script loop:


./mv.sh $pwd $ip


##############################################################

# Remote Service and console interaction via SSH connection

##############################################################

#!/usr/bin/expect-f

Set Timeout 10

Set username root

Set Password Huawei

Set hostname [lindex $argv 0]

Spawn ssh [email protected] $hostname

expect{

#① equivalent to the EXP_CONTINUE directive means that continuing down execution is equivalent to case no break

"Yes/no" {send "yes\r"; Exp_continue}

"Password:" {send "$password \ r"}

}

#匹配控制台以 # End output, execute weighted instruction

Expect "*#"

Send "chmod +x-r remotefile";

Bye

Expect EOF




You can also use the key implementation does not need to enter the password login, but more than one remote need each key

Reference: http://www.linux360.com.cn/html/Linux/tutorial/0554/1392498954.html

Natively

>SSH-KEYGEN-T RSA

Generate public keys and keys #会在 ~/.ssh/

>chmod 755 ~/.ssh-r

#拷贝公钥到远程主. SSH under and renamed Authorized_keys

>SCP ~/.ssh/id_rsa.pub Remoteip:/home/user1/.ssh/authorized_keys



This article is from "Ice Star" blog, please make sure to keep this source http://520bingbing.blog.51cto.com/4244307/1787809

linux-Remote Operation essay

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.