In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the knowledge of "how to log in to a specific directory on Linux by SSH". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
SSH logs in to a specific directory of the remote system
Before I know this method, I usually log in to the remote system first using the following command SSH:
$ssh user@remote-system
Then enter a directory with the following cd:
$cd
However, you do not need to use two separate commands. You can combine and simplify the task with one command.
Look at the following example.
$ssh-t sk@192.168.225.22'cd / home/sk/ostechnix; bash'
The above command connects to the remote system (192.168.225.22) via SSH and immediately enters the directory called / home/sk/ostechnix/ and stays at the prompt.
Here, the-t flag is used to force the allocation of pseudo terminals, which is a necessary interactive shell.
The following is the output of the above command:
You can also use this command:
$ssh-t sk@192.168.225.22'cd / home/sk/ostechnix; exec bash'
Or
$ssh-t sk@192.168.225.22'cd / home/sk/ostechnix & & exec bash-l'
Here, the-l flag sets bash to login shell.
In the above example, I used bash in the latter parameter. It is the default shell on my remote system. If you do not know the shell type on the remote system, use the following command:
$ssh-t sk@192.168.225.22'cd / home/sk/ostechnix & & exec $SHELL'
As I've already said, it's not just about connecting to a remote system and cd going into the directory. You can also use this technique to run other commands. For example, the following command enters / home/sk/ostechnix/, and executes the command uname-a.
$ssh-t sk@192.168.225.22'cd / home/sk/ostechnix & & uname-a & & exec $SHELL'
Alternatively, you can add the commands you want to execute after logging in to SSH in the .bash _ profile file on the remote system.
Edit the .bash _ profile file:
$nano ~ / .bash_profile
One line for each command. In my example, I added the following line:
Cd / home/sk/ostechnix > & / dev/null
Save and close the file. Run the following command to update the changes.
$source ~ / .bash_profile
Note that you should add this line to the .bash _ profile or .bashrc file on the remote system, not on the local system. From now on, whenever you log in (whether via SSH or directly), the cd command will be executed and you will automatically enter the / home/sk/ostechnix/ directory.
This is the end of the content of "how SSH logs in to a specific directory on Linux". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.