Have you ever encountered yourself connecting to a cloud server? After connecting with ssh, you find that some of your gadgets can't be used.
For example, go build cannot be used, because when we install and configure the golang environment, the configuration is written in the file /etc/profile
, so we need source
look at /etc/profile
So is it possible to automatically execute this type of command immediately when ssh connects to the server?
Our wisdom is endless, and there are many gadgets. Today I will tell you how to do multiple commands SSH连接服务器后执行
1 separated by semicolons
Use semicolons ;
to separate commands
with 1 command
ssh User@Host 'source /etc/profile'
Comes with multiple commands
ssh User@Host 'source /etc/profile ; uptime'
2 separated by pipe symbols
Use pipes |
to separate commands
with 1 command
ssh User@Host 'source /etc/profile'
Comes with multiple commands
ssh User@Host 'source /etc/profile | uptime'
3 Use the way of writing EOF
Same for one/many commands
ssh User@Host << EOF
> ls -al
> source /etc/profile
> EOF
4 Ways to use scripts
There are more ways to use scripts. For example, there is a script myinit.sh
under /home/admin/code/
myinit.sh
#!/bin/bash
source /etc/profile
ls -al
remote connection server
ssh User@Host 'bash -s' < /home/admin/code/myinit.sh
The above four methods are available on demand.
The above is the entire content of this issue. If you have any questions, you can ask your questions in the comment area or in the background. We will communicate and grow together.
Good guy, if the article is still useful to you, please help to pay attention, share it to your circle of friends, share technology, and share happiness
Welcome - like, follow, favorite
Friends, your support and encouragement are the motivation for me to persist in sharing and improve quality
Okay, here it is this time
Technology is open, and our mentality should be open. Embrace change, live in the sun, and move forward.
I'm the little devil boy Nezha , welcome to like, follow and collect, see you next time~
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。